package com.android.settings.applications; import com.android.settings.R; import android.app.Activity; import android.app.ActivityManager; import android.app.PendingIntent; import android.content.ActivityNotFoundException; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentSender; import android.content.pm.PackageManager; import android.content.pm.ProviderInfo; import android.content.pm.ServiceInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Resources; import android.os.Bundle; import android.os.Handler; import android.os.HandlerThread; import android.os.Looper; import android.os.Message; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView; import java.util.ArrayList; import java.util.List; public class RunningServiceDetails extends Activity { static final String TAG = "RunningServicesDetails"; static final String KEY_UID = "uid"; static final String KEY_PROCESS = "process"; static final int MSG_UPDATE_TIMES = 1; static final int MSG_UPDATE_CONTENTS = 2; static final int MSG_REFRESH_UI = 3; ActivityManager mAm; LayoutInflater mInflater; RunningState mState; int mUid; String mProcessName; RunningState.MergedItem mMergedItem; ViewGroup mAllDetails; ViewGroup mSnippet; RunningProcessesView.ActiveItem mSnippetActiveItem; RunningProcessesView.ViewHolder mSnippetViewHolder; TextView mServicesHeader; TextView mProcessesHeader; final ArrayList mActiveDetails = new ArrayList(); class ActiveDetail implements View.OnClickListener { View mRootView; RunningProcessesView.ActiveItem mActiveItem; RunningProcessesView.ViewHolder mViewHolder; PendingIntent mManageIntent; public void onClick(View v) { if (mManageIntent != null) { try { startIntentSender(mManageIntent.getIntentSender(), null, Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET, Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET, 0); } catch (IntentSender.SendIntentException e) { Log.w(TAG, e); } catch (IllegalArgumentException e) { Log.w(TAG, e); } catch (ActivityNotFoundException e) { Log.w(TAG, e); } } else { 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 { if (mBackgroundHandler != null) { mBackgroundHandler.sendEmptyMessage(MSG_UPDATE_CONTENTS); } } } } } StringBuilder mBuilder = new StringBuilder(128); HandlerThread mBackgroundThread; final class BackgroundHandler extends Handler { public BackgroundHandler(Looper looper) { super(looper); } @Override public void handleMessage(Message msg) { switch (msg.what) { case MSG_UPDATE_CONTENTS: Message cmd = mHandler.obtainMessage(MSG_REFRESH_UI); cmd.arg1 = mState.update(RunningServiceDetails.this, mAm) ? 1 : 0; mHandler.sendMessage(cmd); removeMessages(MSG_UPDATE_CONTENTS); msg = obtainMessage(MSG_UPDATE_CONTENTS); sendMessageDelayed(msg, RunningProcessesView.CONTENTS_UPDATE_DELAY); break; } } }; BackgroundHandler mBackgroundHandler; final Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case MSG_UPDATE_TIMES: if (mSnippetActiveItem != null) { mSnippetActiveItem.updateTime(RunningServiceDetails.this, mBuilder); } for (int i=0; i newItems = mState.getCurrentMergedItems(); if (newItems != null) { for (int i=0; i=0; i--) { mAllDetails.removeView(mActiveDetails.get(i).mRootView); } mActiveDetails.clear(); if (mServicesHeader != null) { mAllDetails.removeView(mServicesHeader); mServicesHeader = null; } if (mProcessesHeader != null) { mAllDetails.removeView(mProcessesHeader); mProcessesHeader = null; } if (mMergedItem != null) { for (int i=0; i