|
18 | 18 |
|
19 | 19 | import com.android.internal.content.PackageMonitor; |
20 | 20 |
|
| 21 | +import android.app.ActivityManager; |
| 22 | +import android.app.ActivityManagerNative; |
| 23 | +import android.app.AppGlobals; |
21 | 24 | import android.app.ISearchManager; |
22 | 25 | import android.app.SearchManager; |
23 | 26 | import android.app.SearchableInfo; |
|
27 | 30 | import android.content.Context; |
28 | 31 | import android.content.Intent; |
29 | 32 | import android.content.IntentFilter; |
| 33 | +import android.content.pm.IPackageManager; |
| 34 | +import android.content.pm.PackageManager; |
30 | 35 | import android.content.pm.ResolveInfo; |
31 | 36 | import android.database.ContentObserver; |
32 | 37 | import android.os.Binder; |
33 | 38 | import android.os.Process; |
| 39 | +import android.os.RemoteException; |
34 | 40 | import android.os.UserId; |
35 | 41 | import android.os.UserManager; |
36 | 42 | import android.provider.Settings; |
37 | 43 | import android.util.Log; |
| 44 | +import android.util.Slog; |
38 | 45 | import android.util.SparseArray; |
39 | 46 |
|
40 | 47 | import java.util.List; |
@@ -207,4 +214,48 @@ public ComponentName getWebSearchActivity() { |
207 | 214 | return getSearchables(UserId.getCallingUserId()).getWebSearchActivity(); |
208 | 215 | } |
209 | 216 |
|
| 217 | + @Override |
| 218 | + public ComponentName getAssistIntent(int userHandle) { |
| 219 | + try { |
| 220 | + if (userHandle != UserId.getCallingUserId()) { |
| 221 | + // Requesting a different user, make sure that they have the permission |
| 222 | + if (ActivityManager.checkComponentPermission( |
| 223 | + android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, |
| 224 | + Binder.getCallingUid(), -1, true) |
| 225 | + == PackageManager.PERMISSION_GRANTED) { |
| 226 | + // Translate to the current user id, if caller wasn't aware |
| 227 | + if (userHandle == UserId.USER_CURRENT) { |
| 228 | + long identity = Binder.clearCallingIdentity(); |
| 229 | + userHandle = ActivityManagerNative.getDefault().getCurrentUser().id; |
| 230 | + Binder.restoreCallingIdentity(identity); |
| 231 | + } |
| 232 | + } else { |
| 233 | + String msg = "Permission Denial: " |
| 234 | + + "Request to getAssistIntent for " + userHandle |
| 235 | + + " but is calling from user " + UserId.getCallingUserId() |
| 236 | + + "; this requires " |
| 237 | + + android.Manifest.permission.INTERACT_ACROSS_USERS_FULL; |
| 238 | + Slog.w(TAG, msg); |
| 239 | + return null; |
| 240 | + } |
| 241 | + } |
| 242 | + IPackageManager pm = AppGlobals.getPackageManager(); |
| 243 | + Intent assistIntent = new Intent(Intent.ACTION_ASSIST); |
| 244 | + ResolveInfo info = |
| 245 | + pm.resolveIntent(assistIntent, |
| 246 | + assistIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 247 | + PackageManager.MATCH_DEFAULT_ONLY, userHandle); |
| 248 | + if (info != null) { |
| 249 | + return new ComponentName( |
| 250 | + info.activityInfo.applicationInfo.packageName, |
| 251 | + info.activityInfo.name); |
| 252 | + } |
| 253 | + } catch (RemoteException re) { |
| 254 | + // Local call |
| 255 | + Log.e(TAG, "RemoteException in getAssistIntent: " + re); |
| 256 | + } catch (Exception e) { |
| 257 | + Log.e(TAG, "Exception in getAssistIntent: " + e); |
| 258 | + } |
| 259 | + return null; |
| 260 | + } |
210 | 261 | } |
0 commit comments