From b8f9c9cf7c0343c6c05296bb7af8fdccdc3b7a3b Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Wed, 6 Oct 2010 16:46:53 -0700 Subject: [PATCH] Add confirmation when stopping system service, as per rwest. Change-Id: I1cca31a87d3acfc49ffb4562d922d4577c0b1cba --- res/values/strings.xml | 6 + .../applications/RunningServiceDetails.java | 121 ++++++++++++++++----- 2 files changed, 99 insertions(+), 28 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index fbf0e00500..5988e617c7 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1895,6 +1895,12 @@ found in the list of installed applications. Provider %1$s is in use. + + Stop system service? + + Are you sure you want to stop this system service? If you do, some + features of your phone may stop working correctly until you power it off + and then on again. diff --git a/src/com/android/settings/applications/RunningServiceDetails.java b/src/com/android/settings/applications/RunningServiceDetails.java index b8dd10ef05..399c89fe94 100644 --- a/src/com/android/settings/applications/RunningServiceDetails.java +++ b/src/com/android/settings/applications/RunningServiceDetails.java @@ -4,11 +4,14 @@ import com.android.settings.R; import android.app.Activity; import android.app.ActivityManager; +import android.app.AlertDialog; import android.app.ApplicationErrorReport; +import android.app.Dialog; import android.app.PendingIntent; import android.content.ActivityNotFoundException; import android.content.ComponentName; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.IntentSender; import android.content.pm.ApplicationInfo; @@ -19,14 +22,8 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Resources; import android.os.Bundle; import android.os.Debug; -import android.os.Handler; -import android.os.HandlerThread; -import android.os.Looper; -import android.os.Message; -import android.os.Process; import android.os.SystemClock; import android.provider.Settings; -import android.text.format.DateUtils; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -36,11 +33,9 @@ import android.widget.TextView; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; -import java.util.List; public class RunningServiceDetails extends Activity implements RunningState.OnRefreshUiListener { @@ -49,10 +44,13 @@ public class RunningServiceDetails extends Activity static final String KEY_UID = "uid"; static final String KEY_PROCESS = "process"; + static final int DIALOG_CONFIRM_STOP = 1; + ActivityManager mAm; LayoutInflater mInflater; RunningState mState; + boolean mHaveData; int mUid; String mProcessName; @@ -80,6 +78,27 @@ public class RunningServiceDetails extends Activity PendingIntent mManageIntent; ComponentName mInstaller; + void stopActiveService(boolean confirmed) { + RunningState.ServiceItem si = mServiceItem; + if (!confirmed) { + if ((si.mServiceInfo.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0) { + Bundle args = new Bundle(); + args.putParcelable("comp", si.mRunningService.service); + removeDialog(DIALOG_CONFIRM_STOP); + showDialog(DIALOG_CONFIRM_STOP, args); + return; + } + } + stopService(new Intent().setComponent(si.mRunningService.service)); + if (mMergedItem == null || mMergedItem.mServices.size() <= 1) { + // If there was only one service, we are finishing it, + // so no reason for the UI to stick around. + finish(); + } else { + mState.updateNow(); + } + } + public void onClick(View v) { if (v == mReportButton) { ApplicationErrorReport report = new ApplicationErrorReport(); @@ -145,16 +164,8 @@ public class RunningServiceDetails extends Activity } catch (ActivityNotFoundException e) { Log.w(TAG, e); } - } else if (mActiveItem.mItem instanceof RunningState.ServiceItem) { - RunningState.ServiceItem si = (RunningState.ServiceItem)mActiveItem.mItem; - stopService(new Intent().setComponent(si.mRunningService.service)); - if (mMergedItem == null || mMergedItem.mServices.size() <= 1) { - // If there was only one service, we are finishing it, - // so no reason for the UI to stick around. - finish(); - } else { - mState.updateNow(); - } + } else if (mServiceItem != null) { + stopActiveService(false); } else { // Heavy-weight process. We'll do a force-stop on it. mAm.forceStopPackage(mActiveItem.mItem.mPackageInfo.packageName); @@ -398,34 +409,88 @@ public class RunningServiceDetails extends Activity mSnippet.setBackgroundResource(com.android.internal.R.drawable.title_bar_medium); mSnippet.setPadding(0, mSnippet.getPaddingTop(), 0, mSnippet.getPaddingBottom()); mSnippetViewHolder = new RunningProcessesView.ViewHolder(mSnippet); + + // We want to retrieve the data right now, so any active managed + // dialog that gets created can find it. + ensureData(); } @Override protected void onPause() { super.onPause(); + mHaveData = false; mState.pause(); } @Override protected void onResume() { super.onResume(); - mState.resume(this); - - // We want to go away if the service being shown no longer exists, - // so we need to ensure we have done the initial data retrieval before - // showing our ui. - mState.waitForData(); - - // And since we know we have the data, let's show the UI right away - // to avoid flicker. - refreshUi(true); + ensureData(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); } + + ActiveDetail activeDetailForService(ComponentName comp) { + for (int i=0; i