-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ryan Bailey
committed
Feb 28, 2016
1 parent
cd2a96a
commit 9a68cf9
Showing
9 changed files
with
15 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
app/src/androidTest/java/com/rbware/androiddatetime/ApplicationTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,28 @@ | ||
package com.rbware.androiddatetime; | ||
package com.rbware.firetvreboot; | ||
|
||
import android.app.Activity; | ||
import android.os.AsyncTask; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.widget.Toast; | ||
|
||
import org.apache.http.HttpResponse; | ||
import org.apache.http.HttpStatus; | ||
import org.apache.http.StatusLine; | ||
import org.apache.http.client.ClientProtocolException; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.impl.client.DefaultHttpClient; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
import java.net.InetAddress; | ||
import java.util.Date; | ||
|
||
|
||
public class Main extends Activity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
// Run Root Command to set date/time | ||
new RequestTask().execute("http://www.timeapi.org/cdt/now"); // CDT | ||
} | ||
|
||
private class RequestTask extends AsyncTask<String, String, String> { | ||
|
||
@Override | ||
protected String doInBackground(String... uri) { | ||
HttpClient httpclient = new DefaultHttpClient(); | ||
HttpResponse response; | ||
String responseString = null; | ||
try { | ||
response = httpclient.execute(new HttpGet(uri[0])); | ||
StatusLine statusLine = response.getStatusLine(); | ||
if(statusLine.getStatusCode() == HttpStatus.SC_OK){ | ||
ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
response.getEntity().writeTo(out); | ||
out.close(); | ||
responseString = out.toString(); | ||
} else{ | ||
//Closes the connection. | ||
response.getEntity().getContent().close(); | ||
throw new IOException(statusLine.getReasonPhrase()); | ||
} | ||
} catch (ClientProtocolException e) { | ||
//TODO Handle problems.. | ||
} catch (IOException e) { | ||
//TODO Handle problems.. | ||
} | ||
return responseString; | ||
} | ||
|
||
@Override | ||
protected void onPostExecute(String result) { | ||
super.onPostExecute(result); | ||
|
||
// Parse | ||
String properFormat = getSuFormat(result); | ||
|
||
// Set date properly using SU | ||
// adb shell 'su 0 date -s 20140825.134241' | ||
String suCommand = "su 0 date -s " + properFormat; | ||
try { | ||
Process process = Runtime.getRuntime().exec("su"); | ||
DataOutputStream os = new DataOutputStream(process.getOutputStream()); | ||
os.writeBytes("date -s " + properFormat + "; \n"); | ||
} catch (Exception ex) { | ||
Log.i("Settings", "Could not reboot", ex); | ||
} | ||
|
||
// Quit everything | ||
Toast.makeText(Main.this, "Date and Time Updated", Toast.LENGTH_SHORT).show(); | ||
Main.this.finish(); | ||
} | ||
|
||
private String getSuFormat(String input){ | ||
String output = ""; | ||
// 2014-08-25T14:11:34-05:00 | ||
output = input.substring(0, input.indexOf("T")); | ||
output = output.replace("-", ""); | ||
output += "."; | ||
output += input.substring(input.indexOf("T") + 1, input.lastIndexOf("-")); | ||
output = output.replace(":", ""); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
|
||
return output; | ||
try { | ||
Runtime.getRuntime().exec(new String[]{"su", "-c", "reboot now"}); | ||
} catch (IOException e){ | ||
Toast.makeText(this, "Could not reboot your device", Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<string name="app_name">AndroidDateTime</string> | ||
<string name="hello_world">Hello world!</string> | ||
<string name="action_settings">Settings</string> | ||
<string name="app_name">FireTV Reboot</string> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Wed Apr 10 15:27:10 PDT 2013 | ||
#Sun Feb 28 10:23:25 CST 2016 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters