Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Reboot from notification
Browse files Browse the repository at this point in the history
Closes #1382
  • Loading branch information
M66B committed Feb 18, 2014
1 parent cd544ff commit 343bbb7
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Changelog
* Added option to fake [GSM CID/LAC](http://en.wikipedia.org/wiki/Cell_ID) ([issue](/../../issues/1289))
* Note: only [cell locations](http://developer.android.com/reference/android/telephony/CellLocation.html) can be faked, not [cell info](http://developer.android.com/reference/android/telephony/CellInfo.html)
* *Apply to entire category* and *Once for ... seconds* exclude each other ([issue](/../../issues/1381))
* Notification *Restart required* will ask to reboot ([issue](/../../issues/1382))
* Updated Slovak translation

[Open issues](https://github.com/M66B/XPrivacy/issues?state=open)
Expand Down
41 changes: 41 additions & 0 deletions src/biz/bokhorst/xprivacy/ActivityMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public class ActivityMain extends ActivityBase implements OnItemSelectedListener

private Handler mProHandler = new Handler();

public static final String cAction = "Action";
public static final int cActionReboot = 1;

public static final int STATE_ATTENTION = 0;
public static final int STATE_CHANGED = 1;
public static final int STATE_SHARED = 2;
Expand Down Expand Up @@ -287,6 +290,12 @@ public void onClick(View view) {
};
((Button) findViewById(R.id.btnTutorialHeader)).setOnClickListener(listener);
((Button) findViewById(R.id.btnTutorialDetails)).setOnClickListener(listener);

// Process actions
Bundle extras = getIntent().getExtras();
if (extras != null && extras.containsKey(cAction))
if (extras.getInt(cAction) == cActionReboot)
reboot();
}

@Override
Expand All @@ -298,6 +307,14 @@ protected void onResume() {

@Override
protected void onNewIntent(Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null && extras.containsKey(cAction))
if (extras.getInt(cAction) == cActionReboot) {
setIntent(intent);
recreate();
return;
}

if (mAppAdapter != null)
mAppAdapter.notifyDataSetChanged();
}
Expand Down Expand Up @@ -980,6 +997,30 @@ private void optionTutorial() {
PrivacyManager.setSetting(0, PrivacyManager.cSettingTutorialMain, Boolean.FALSE.toString());
}

private void reboot() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityMain.this);
alertDialogBuilder.setTitle(R.string.msg_reboot);
alertDialogBuilder.setMessage(R.string.msg_sure);
alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
alertDialogBuilder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
PrivacyService.getClient().reboot();
} catch (Throwable ex) {
Util.bug(null, ex);
}
}
});
alertDialogBuilder.setNegativeButton(getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}

// Tasks

private class AppListTask extends AsyncTask<Object, Integer, List<ApplicationInfoEx>> {
Expand Down
1 change: 1 addition & 0 deletions src/biz/bokhorst/xprivacy/IPrivacyService.aidl
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ interface IPrivacyService {
void deleteSettings(int uid);

void clear();
void reboot();
}
8 changes: 8 additions & 0 deletions src/biz/bokhorst/xprivacy/PackageChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,19 @@ public void onReceive(final Context context, Intent intent) {
changeIntent.putExtra(UpdateService.cAction, UpdateService.cActionUpdated);
context.startService(changeIntent);

Intent resultIntent = new Intent(context, ActivityMain.class);
resultIntent.putExtra(ActivityMain.cAction, ActivityMain.cActionReboot);

// Build pending intent
PendingIntent pendingIntent = PendingIntent.getActivity(context, uid, resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT);

// Build notification
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);
notificationBuilder.setSmallIcon(R.drawable.ic_launcher);
notificationBuilder.setContentTitle(context.getString(R.string.app_name));
notificationBuilder.setContentText(context.getString(R.string.msg_reboot));
notificationBuilder.setContentIntent(pendingIntent);
notificationBuilder.setWhen(System.currentTimeMillis());
notificationBuilder.setAutoCancel(true);
Notification notification = notificationBuilder.build();
Expand Down
13 changes: 13 additions & 0 deletions src/biz/bokhorst/xprivacy/PrivacyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.PowerManager;
import android.os.Process;
import android.os.RemoteException;
import android.os.StrictMode;
Expand Down Expand Up @@ -1088,6 +1089,18 @@ public void clear() throws RemoteException {
}
}

@Override
public void reboot() throws RemoteException {
try {
enforcePermission();
Binder.clearCallingIdentity();
PowerManager pm = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE);
pm.reboot(null);
} catch (Throwable ex) {
Util.bug(null, ex);
}
}

// Helper methods

private void onDemandDialog(final Hook hook, final PRestriction restriction, final PRestriction result) {
Expand Down

0 comments on commit 343bbb7

Please sign in to comment.