diff options
author | Dianne Hackborn <hackbod@google.com> | 2014-05-02 20:18:10 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-05-02 20:18:10 +0000 |
commit | 5b8b92002230525317d5832a84d7813467594967 (patch) | |
tree | dbb5b24e560210149bcce3e2cffb7897f370207d /services/core/java/com/android/server | |
parent | 4f854e0d0b619596752b1874492efe2dabcc092b (diff) | |
parent | 09233289624a85093b1d99e4a6a149bf09059d8d (diff) | |
download | frameworks_base-5b8b92002230525317d5832a84d7813467594967.zip frameworks_base-5b8b92002230525317d5832a84d7813467594967.tar.gz frameworks_base-5b8b92002230525317d5832a84d7813467594967.tar.bz2 |
Merge "Make GET_TASKS signature|system."
Diffstat (limited to 'services/core/java/com/android/server')
6 files changed, 36 insertions, 277 deletions
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 9eaddbd..042bf5f 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -95,7 +95,6 @@ import android.app.INotificationManager; import android.app.IProcessObserver; import android.app.IServiceConnection; import android.app.IStopUserCallback; -import android.app.IThumbnailReceiver; import android.app.IUiAutomationConnection; import android.app.IUserSwitchObserver; import android.app.Instrumentation; @@ -703,13 +702,6 @@ public final class ActivityManagerService extends ActivityManagerNative String mBackupAppName = null; BackupRecord mBackupTarget = null; - /** - * List of PendingThumbnailsRecord objects of clients who are still - * waiting to receive all of the thumbnails for a task. - */ - final ArrayList<PendingThumbnailsRecord> mPendingThumbnails = - new ArrayList<PendingThumbnailsRecord>(); - final ProviderMap mProviderMap; /** @@ -5452,21 +5444,15 @@ public final class ActivityManagerService extends ActivityManagerNative throw new IllegalArgumentException("File descriptors passed in Bundle"); } - ActivityRecord r = null; - final long origId = Binder.clearCallingIdentity(); synchronized (this) { - r = ActivityRecord.isInStackLocked(token); + ActivityRecord r = ActivityRecord.isInStackLocked(token); if (r != null) { r.task.stack.activityStoppedLocked(r, icicle, thumbnail, description); } } - if (r != null) { - sendPendingThumbnail(r, null, null, null, false); - } - trimApplications(); Binder.restoreCallingIdentity(origId); @@ -6982,66 +6968,24 @@ public final class ActivityManagerService extends ActivityManagerNative // ========================================================= @Override - public List<RunningTaskInfo> getTasks(int maxNum, int flags, - IThumbnailReceiver receiver) { + public List<RunningTaskInfo> getTasks(int maxNum, int flags) { + final int callingUid = Binder.getCallingUid(); ArrayList<RunningTaskInfo> list = new ArrayList<RunningTaskInfo>(); - PendingThumbnailsRecord pending = new PendingThumbnailsRecord(receiver); - ActivityRecord topRecord = null; - synchronized(this) { if (localLOGV) Slog.v( - TAG, "getTasks: max=" + maxNum + ", flags=" + flags - + ", receiver=" + receiver); + TAG, "getTasks: max=" + maxNum + ", flags=" + flags); - if (checkCallingPermission(android.Manifest.permission.GET_TASKS) - != PackageManager.PERMISSION_GRANTED) { - if (receiver != null) { - // If the caller wants to wait for pending thumbnails, - // it ain't gonna get them. - try { - receiver.finished(); - } catch (RemoteException ex) { - } - } - String msg = "Permission Denial: getTasks() from pid=" - + Binder.getCallingPid() - + ", uid=" + Binder.getCallingUid() - + " requires " + android.Manifest.permission.GET_TASKS; - Slog.w(TAG, msg); - throw new SecurityException(msg); + final boolean allowed = checkCallingPermission( + android.Manifest.permission.GET_TASKS) + == PackageManager.PERMISSION_GRANTED; + if (!allowed) { + Slog.w(TAG, "getTasks: caller " + callingUid + + " does not hold GET_TASKS; limiting output"); } // TODO: Improve with MRU list from all ActivityStacks. - topRecord = mStackSupervisor.getTasksLocked(maxNum, receiver, pending, list); - - if (!pending.pendingRecords.isEmpty()) { - mPendingThumbnails.add(pending); - } - } - - if (localLOGV) Slog.v(TAG, "We have pending thumbnails: " + pending); - - if (topRecord != null) { - if (localLOGV) Slog.v(TAG, "Requesting top thumbnail"); - try { - IApplicationThread topThumbnail = topRecord.app.thread; - topThumbnail.requestThumbnail(topRecord.appToken); - } catch (Exception e) { - Slog.w(TAG, "Exception thrown when requesting thumbnail", e); - sendPendingThumbnail(null, topRecord.appToken, null, null, true); - } - } - - if (pending.pendingRecords.isEmpty() && receiver != null) { - // In this case all thumbnails were available and the client - // is being asked to be told when the remaining ones come in... - // which is unusually, since the top-most currently running - // activity should never have a canned thumbnail! Oh well. - try { - receiver.finished(); - } catch (RemoteException ex) { - } + mStackSupervisor.getTasksLocked(maxNum, list, callingUid, allowed); } return list; @@ -7054,12 +6998,18 @@ public final class ActivityManagerService extends ActivityManagerNative @Override public List<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum, int flags, int userId) { - userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, + final int callingUid = Binder.getCallingUid(); + userId = handleIncomingUser(Binder.getCallingPid(), callingUid, userId, false, true, "getRecentTasks", null); synchronized (this) { - enforceCallingPermission(android.Manifest.permission.GET_TASKS, - "getRecentTasks()"); + final boolean allowed = checkCallingPermission( + android.Manifest.permission.GET_TASKS) + == PackageManager.PERMISSION_GRANTED; + if (!allowed) { + Slog.w(TAG, "getRecentTasks: caller " + callingUid + + " does not hold GET_TASKS; limiting output"); + } final boolean detailed = checkCallingPermission( android.Manifest.permission.GET_DETAILED_TASKS) == PackageManager.PERMISSION_GRANTED; @@ -7094,6 +7044,13 @@ public final class ActivityManagerService extends ActivityManagerNative || (tr.intent == null) || ((tr.intent.getFlags() &Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0)) { + if (!allowed) { + // If the caller doesn't have the GET_TASKS permission, then only + // allow them to see a small subset of tasks -- their own and home. + if (!tr.isHomeTask() && tr.creatorUid != callingUid) { + continue; + } + } ActivityManager.RecentTaskInfo rti = new ActivityManager.RecentTaskInfo(); rti.id = tr.numActivities > 0 ? tr.taskId : -1; @@ -7635,82 +7592,6 @@ public final class ActivityManagerService extends ActivityManagerNative } // ========================================================= - // THUMBNAILS - // ========================================================= - - public void reportThumbnail(IBinder token, - Bitmap thumbnail, CharSequence description) { - //System.out.println("Report thumbnail for " + token + ": " + thumbnail); - final long origId = Binder.clearCallingIdentity(); - sendPendingThumbnail(null, token, thumbnail, description, true); - Binder.restoreCallingIdentity(origId); - } - - final void sendPendingThumbnail(ActivityRecord r, IBinder token, - Bitmap thumbnail, CharSequence description, boolean always) { - TaskRecord task; - ArrayList<PendingThumbnailsRecord> receivers = null; - - //System.out.println("Send pending thumbnail: " + r); - - synchronized(this) { - if (r == null) { - r = ActivityRecord.isInStackLocked(token); - if (r == null) { - return; - } - } - if (thumbnail == null && r.thumbHolder != null) { - thumbnail = r.thumbHolder.lastThumbnail; - description = r.thumbHolder.lastDescription; - } - if (thumbnail == null && !always) { - // If there is no thumbnail, and this entry is not actually - // going away, then abort for now and pick up the next - // thumbnail we get. - return; - } - task = r.task; - - int N = mPendingThumbnails.size(); - int i=0; - while (i<N) { - PendingThumbnailsRecord pr = mPendingThumbnails.get(i); - //System.out.println("Looking in " + pr.pendingRecords); - if (pr.pendingRecords.remove(r)) { - if (receivers == null) { - receivers = new ArrayList<PendingThumbnailsRecord>(); - } - receivers.add(pr); - if (pr.pendingRecords.size() == 0) { - pr.finished = true; - mPendingThumbnails.remove(i); - N--; - continue; - } - } - i++; - } - } - - if (receivers != null) { - final int N = receivers.size(); - for (int i=0; i<N; i++) { - try { - PendingThumbnailsRecord pr = receivers.get(i); - pr.receiver.newThumbnail( - task != null ? task.taskId : -1, thumbnail, description); - if (pr.finished) { - pr.receiver.finished(); - } - } catch (Exception e) { - Slog.w(TAG, "Exception thrown when sending thumbnail", e); - } - } - } - } - - // ========================================================= // CONTENT PROVIDERS // ========================================================= diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java index 7a44473..7a08cdd 100755 --- a/services/core/java/com/android/server/am/ActivityRecord.java +++ b/services/core/java/com/android/server/am/ActivityRecord.java @@ -131,7 +131,6 @@ final class ActivityRecord { boolean sleeping; // have we told the activity to sleep? boolean waitingVisible; // true if waiting for a new act to become vis boolean nowVisible; // is this activity's window visible? - boolean thumbnailNeeded;// has someone requested a thumbnail? boolean idle; // has the activity gone idle? boolean hasBeenLaunched;// has this activity ever been launched? boolean frozenBeforeDestroy;// has been frozen but not yet destroyed. @@ -239,7 +238,6 @@ final class ActivityRecord { pw.print(" immersive="); pw.print(immersive); pw.print(" launchMode="); pw.println(launchMode); pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy); - pw.print(" thumbnailNeeded="); pw.print(thumbnailNeeded); pw.print(" forceNewConfig="); pw.println(forceNewConfig); pw.print(prefix); pw.print("mActivityType="); pw.println(activityTypeToString(mActivityType)); @@ -375,7 +373,6 @@ final class ActivityRecord { visible = true; waitingVisible = false; nowVisible = false; - thumbnailNeeded = false; idle = false; hasBeenLaunched = false; mStackSupervisor = supervisor; diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java index 6769c9c..5beb17d 100755 --- a/services/core/java/com/android/server/am/ActivityStack.java +++ b/services/core/java/com/android/server/am/ActivityStack.java @@ -53,7 +53,6 @@ import android.app.ActivityManager; import android.app.ActivityOptions; import android.app.AppGlobals; import android.app.IActivityController; -import android.app.IThumbnailReceiver; import android.app.ResultInfo; import android.app.ActivityManager.RunningTaskInfo; import android.content.ComponentName; @@ -73,7 +72,6 @@ import android.os.Looper; import android.os.Message; import android.os.RemoteException; import android.os.SystemClock; -import android.os.SystemProperties; import android.os.Trace; import android.os.UserHandle; import android.util.EventLog; @@ -2537,13 +2535,6 @@ final class ActivityStack { finishActivityResultsLocked(r, resultCode, resultData); - if (!mService.mPendingThumbnails.isEmpty()) { - // There are clients waiting to receive thumbnails so, in case - // this is an activity that someone is waiting for, add it - // to the pending list so we can correctly update the clients. - mStackSupervisor.mCancelledThumbnails.add(r); - } - if (mResumedActivity == r) { boolean endTask = index <= 0; if (DEBUG_VISBILITY || DEBUG_TRANSITION) Slog.v(TAG, @@ -2782,13 +2773,6 @@ final class ActivityStack { cleanUpActivityServicesLocked(r); } - if (!mService.mPendingThumbnails.isEmpty()) { - // There are clients waiting to receive thumbnails so, in case - // this is an activity that someone is waiting for, add it - // to the pending list so we can correctly update the clients. - mStackSupervisor.mCancelledThumbnails.add(r); - } - // Get rid of any pending idle timeouts. removeTimeoutsForActivityLocked(r); } @@ -3535,9 +3519,7 @@ final class ActivityStack { return didSomething; } - ActivityRecord getTasksLocked(IThumbnailReceiver receiver, - PendingThumbnailsRecord pending, List<RunningTaskInfo> list) { - ActivityRecord topRecord = null; + void getTasksLocked(List<RunningTaskInfo> list, int callingUid, boolean allowed) { for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { final TaskRecord task = mTaskHistory.get(taskNdx); ActivityRecord r = null; @@ -3548,6 +3530,9 @@ final class ActivityStack { if (activities.isEmpty()) { continue; } + if (!allowed && !task.isHomeTask() && task.creatorUid != callingUid) { + continue; + } for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { r = activities.get(activityNdx); @@ -3581,23 +3566,8 @@ final class ActivityStack { ci.numRunning = numRunning; //System.out.println( // "#" + maxNum + ": " + " descr=" + ci.description); - if (receiver != null) { - if (localLOGV) Slog.v( - TAG, "State=" + top.state + "Idle=" + top.idle - + " app=" + top.app - + " thr=" + (top.app != null ? top.app.thread : null)); - if (top.state == ActivityState.RESUMED || top.state == ActivityState.PAUSING) { - if (top.idle && top.app != null && top.app.thread != null) { - topRecord = top; - } else { - top.thumbnailNeeded = true; - } - } - pending.pendingRecords.add(top); - } list.add(ci); } - return topRecord; } public void unhandledBackLocked() { diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index 3770a07..9107cb6 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -41,7 +41,6 @@ import android.app.IActivityContainer; import android.app.IActivityContainerCallback; import android.app.IActivityManager; import android.app.IApplicationThread; -import android.app.IThumbnailReceiver; import android.app.PendingIntent; import android.app.ActivityManager.RunningTaskInfo; import android.app.IActivityManager.WaitResult; @@ -191,10 +190,6 @@ public final class ActivityStackSupervisor implements DisplayListener { /** List of activities that are in the process of going to sleep. */ final ArrayList<ActivityRecord> mGoingToSleepActivities = new ArrayList<ActivityRecord>(); - /** List of ActivityRecord objects that have been finished and must still report back to a - * pending thumbnail receiver. */ - final ArrayList<ActivityRecord> mCancelledThumbnails = new ArrayList<ActivityRecord>(); - /** Used on user changes */ final ArrayList<UserStartedState> mStartingUsers = new ArrayList<UserStartedState>(); @@ -591,10 +586,7 @@ public final class ActivityStackSupervisor implements DisplayListener { return null; } - ActivityRecord getTasksLocked(int maxNum, IThumbnailReceiver receiver, - PendingThumbnailsRecord pending, List<RunningTaskInfo> list) { - ActivityRecord r = null; - + void getTasksLocked(int maxNum, List<RunningTaskInfo> list, int callingUid, boolean allowed) { // Gather all of the running tasks for each stack into runningTaskLists. ArrayList<ArrayList<RunningTaskInfo>> runningTaskLists = new ArrayList<ArrayList<RunningTaskInfo>>(); @@ -605,10 +597,7 @@ public final class ActivityStackSupervisor implements DisplayListener { final ActivityStack stack = stacks.get(stackNdx); ArrayList<RunningTaskInfo> stackTaskList = new ArrayList<RunningTaskInfo>(); runningTaskLists.add(stackTaskList); - final ActivityRecord ar = stack.getTasksLocked(receiver, pending, stackTaskList); - if (r == null && isFrontStack(stack)) { - r = ar; - } + stack.getTasksLocked(stackTaskList, callingUid, allowed); } } @@ -635,8 +624,6 @@ public final class ActivityStackSupervisor implements DisplayListener { break; } } - - return r; } ActivityInfo resolveActivity(Intent intent, String resolvedType, int startFlags, @@ -1912,7 +1899,6 @@ public final class ActivityStackSupervisor implements DisplayListener { ArrayList<UserStartedState> startingUsers = null; int NS = 0; int NF = 0; - IApplicationThread sendThumbnail = null; boolean booting = false; boolean enableScreen = false; boolean activityRemoved = false; @@ -1940,11 +1926,6 @@ public final class ActivityStackSupervisor implements DisplayListener { // us, we can now deliver. r.idle = true; - if (r.thumbnailNeeded && r.app != null && r.app.thread != null) { - sendThumbnail = r.app.thread; - r.thumbnailNeeded = false; - } - //Slog.i(TAG, "IDLE: mBooted=" + mBooted + ", fromTimeout=" + fromTimeout); if (!mService.mBooted && isFrontStack(r.task.stack)) { mService.mBooted = true; @@ -1976,15 +1957,6 @@ public final class ActivityStackSupervisor implements DisplayListener { mFinishingActivities.clear(); } - final ArrayList<ActivityRecord> thumbnails; - final int NT = mCancelledThumbnails.size(); - if (NT > 0) { - thumbnails = new ArrayList<ActivityRecord>(mCancelledThumbnails); - mCancelledThumbnails.clear(); - } else { - thumbnails = null; - } - if (isFrontStack(mHomeStack)) { booting = mService.mBooting; mService.mBooting = false; @@ -1995,28 +1967,6 @@ public final class ActivityStackSupervisor implements DisplayListener { mStartingUsers.clear(); } - // Perform the following actions from unsynchronized state. - final IApplicationThread thumbnailThread = sendThumbnail; - mHandler.post(new Runnable() { - @Override - public void run() { - if (thumbnailThread != null) { - try { - thumbnailThread.requestThumbnail(token); - } catch (Exception e) { - Slog.w(TAG, "Exception thrown when requesting thumbnail", e); - mService.sendPendingThumbnail(null, token, null, null, true); - } - } - - // Report back to any thumbnail receivers. - for (int i = 0; i < NT; i++) { - ActivityRecord r = thumbnails.get(i); - mService.sendPendingThumbnail(r, null, null, null, true); - } - } - }); - // Stop any activities that are scheduled to do so but have been // waiting for the next one to start. for (int i = 0; i < NS; i++) { diff --git a/services/core/java/com/android/server/am/PendingThumbnailsRecord.java b/services/core/java/com/android/server/am/PendingThumbnailsRecord.java deleted file mode 100644 index e4eb4d0..0000000 --- a/services/core/java/com/android/server/am/PendingThumbnailsRecord.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2006 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.server.am; - -import android.app.IThumbnailReceiver; - -import java.util.HashSet; - -/** - * This class keeps track of calls to getTasks() that are still - * waiting for thumbnail images. - */ -final class PendingThumbnailsRecord -{ - final IThumbnailReceiver receiver; // who is waiting. - final HashSet<ActivityRecord> pendingRecords; // HistoryRecord objects we still wait for. - boolean finished; // Is pendingRecords empty? - - PendingThumbnailsRecord(IThumbnailReceiver _receiver) - { - receiver = _receiver; - pendingRecords = new HashSet<ActivityRecord>(); - finished = false; - } -} diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java index 68da54d..f4dd15e 100644 --- a/services/core/java/com/android/server/am/TaskRecord.java +++ b/services/core/java/com/android/server/am/TaskRecord.java @@ -52,6 +52,7 @@ final class TaskRecord extends ThumbnailHolder { String stringName; // caching of toString() result. int userId; // user for which this task was created + int creatorUid; // The app uid that originally created the task int numFullscreen; // Number of fullscreen activities. @@ -131,9 +132,8 @@ final class TaskRecord extends ThumbnailHolder { rootWasReset = true; } - if (info.applicationInfo != null) { - userId = UserHandle.getUserId(info.applicationInfo.uid); - } + userId = UserHandle.getUserId(info.applicationInfo.uid); + creatorUid = info.applicationInfo.uid; } void disposeThumbnail() { |