diff options
author | Amith Yamasani <yamasani@google.com> | 2012-08-14 09:32:02 -0700 |
---|---|---|
committer | Amith Yamasani <yamasani@google.com> | 2012-08-14 12:39:29 -0700 |
commit | c1d07a4bd26c0ecf87bfa151ae43cb92c0c73791 (patch) | |
tree | 620e4b1cf4e7534b41ea94f9ac3732fa622e4670 /core/java/android/server | |
parent | b26295b7a0bc23deb2987c4ff10810c3ce2f1869 (diff) | |
download | frameworks_base-c1d07a4bd26c0ecf87bfa151ae43cb92c0c73791.zip frameworks_base-c1d07a4bd26c0ecf87bfa151ae43cb92c0c73791.tar.gz frameworks_base-c1d07a4bd26c0ecf87bfa151ae43cb92c0c73791.tar.bz2 |
Launch ASSIST intent on the current user
Lockscreen and statusbar now launch the intent on the current user.
Make sure that the intent resolution is made to the package manager
for the specific user, as the app could have been disabled for that
user or may have an alternative app installed.
Change-Id: I93b0f972d6c7e8880b146da83dc3d08a68fe7e51
Diffstat (limited to 'core/java/android/server')
-rw-r--r-- | core/java/android/server/search/SearchManagerService.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/core/java/android/server/search/SearchManagerService.java b/core/java/android/server/search/SearchManagerService.java index a1f6735..b4f5e12 100644 --- a/core/java/android/server/search/SearchManagerService.java +++ b/core/java/android/server/search/SearchManagerService.java @@ -18,6 +18,9 @@ package android.server.search; import com.android.internal.content.PackageMonitor; +import android.app.ActivityManager; +import android.app.ActivityManagerNative; +import android.app.AppGlobals; import android.app.ISearchManager; import android.app.SearchManager; import android.app.SearchableInfo; @@ -27,14 +30,18 @@ import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.IPackageManager; +import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.database.ContentObserver; import android.os.Binder; import android.os.Process; +import android.os.RemoteException; import android.os.UserId; import android.os.UserManager; import android.provider.Settings; import android.util.Log; +import android.util.Slog; import android.util.SparseArray; import java.util.List; @@ -207,4 +214,48 @@ public class SearchManagerService extends ISearchManager.Stub { return getSearchables(UserId.getCallingUserId()).getWebSearchActivity(); } + @Override + public ComponentName getAssistIntent(int userHandle) { + try { + if (userHandle != UserId.getCallingUserId()) { + // Requesting a different user, make sure that they have the permission + if (ActivityManager.checkComponentPermission( + android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, + Binder.getCallingUid(), -1, true) + == PackageManager.PERMISSION_GRANTED) { + // Translate to the current user id, if caller wasn't aware + if (userHandle == UserId.USER_CURRENT) { + long identity = Binder.clearCallingIdentity(); + userHandle = ActivityManagerNative.getDefault().getCurrentUser().id; + Binder.restoreCallingIdentity(identity); + } + } else { + String msg = "Permission Denial: " + + "Request to getAssistIntent for " + userHandle + + " but is calling from user " + UserId.getCallingUserId() + + "; this requires " + + android.Manifest.permission.INTERACT_ACROSS_USERS_FULL; + Slog.w(TAG, msg); + return null; + } + } + IPackageManager pm = AppGlobals.getPackageManager(); + Intent assistIntent = new Intent(Intent.ACTION_ASSIST); + ResolveInfo info = + pm.resolveIntent(assistIntent, + assistIntent.resolveTypeIfNeeded(mContext.getContentResolver()), + PackageManager.MATCH_DEFAULT_ONLY, userHandle); + if (info != null) { + return new ComponentName( + info.activityInfo.applicationInfo.packageName, + info.activityInfo.name); + } + } catch (RemoteException re) { + // Local call + Log.e(TAG, "RemoteException in getAssistIntent: " + re); + } catch (Exception e) { + Log.e(TAG, "Exception in getAssistIntent: " + e); + } + return null; + } } |