Search in sources :

Example 86 with ComponentName

use of android.content.ComponentName in project platform_frameworks_base by android.

the class UsbConfirmActivity method onClick.

public void onClick(DialogInterface dialog, int which) {
    if (which == AlertDialog.BUTTON_POSITIVE) {
        try {
            IBinder b = ServiceManager.getService(USB_SERVICE);
            IUsbManager service = IUsbManager.Stub.asInterface(b);
            final int uid = mResolveInfo.activityInfo.applicationInfo.uid;
            final int userId = UserHandle.myUserId();
            boolean alwaysUse = mAlwaysUse.isChecked();
            Intent intent = null;
            if (mDevice != null) {
                intent = new Intent(UsbManager.ACTION_USB_DEVICE_ATTACHED);
                intent.putExtra(UsbManager.EXTRA_DEVICE, mDevice);
                // grant permission for the device
                service.grantDevicePermission(mDevice, uid);
                // set or clear default setting
                if (alwaysUse) {
                    service.setDevicePackage(mDevice, mResolveInfo.activityInfo.packageName, userId);
                } else {
                    service.setDevicePackage(mDevice, null, userId);
                }
            } else if (mAccessory != null) {
                intent = new Intent(UsbManager.ACTION_USB_ACCESSORY_ATTACHED);
                intent.putExtra(UsbManager.EXTRA_ACCESSORY, mAccessory);
                // grant permission for the accessory
                service.grantAccessoryPermission(mAccessory, uid);
                // set or clear default setting
                if (alwaysUse) {
                    service.setAccessoryPackage(mAccessory, mResolveInfo.activityInfo.packageName, userId);
                } else {
                    service.setAccessoryPackage(mAccessory, null, userId);
                }
            }
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setComponent(new ComponentName(mResolveInfo.activityInfo.packageName, mResolveInfo.activityInfo.name));
            startActivityAsUser(intent, new UserHandle(userId));
        } catch (Exception e) {
            Log.e(TAG, "Unable to start activity", e);
        }
    }
    finish();
}
Also used : IBinder(android.os.IBinder) UserHandle(android.os.UserHandle) Intent(android.content.Intent) ComponentName(android.content.ComponentName) IUsbManager(android.hardware.usb.IUsbManager)

Example 87 with ComponentName

use of android.content.ComponentName in project platform_frameworks_base by android.

the class TileServiceManagerTests method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mThread = new HandlerThread("TestThread");
    mThread.start();
    mHandler = new Handler(mThread.getLooper());
    mTileServices = Mockito.mock(TileServices.class);
    Mockito.when(mTileServices.getContext()).thenReturn(mContext);
    mTileLifecycle = Mockito.mock(TileLifecycleManager.class);
    Mockito.when(mTileLifecycle.isActiveTile()).thenReturn(false);
    ComponentName componentName = new ComponentName(mContext, TileServiceManagerTests.class);
    Mockito.when(mTileLifecycle.getComponent()).thenReturn(componentName);
    mTileServiceManager = new TileServiceManager(mTileServices, mHandler, mTileLifecycle);
}
Also used : HandlerThread(android.os.HandlerThread) Handler(android.os.Handler) ComponentName(android.content.ComponentName)

Example 88 with ComponentName

use of android.content.ComponentName in project platform_frameworks_base by android.

the class TextServicesManagerService method buildSpellCheckerMapLocked.

private static void buildSpellCheckerMapLocked(Context context, ArrayList<SpellCheckerInfo> list, HashMap<String, SpellCheckerInfo> map, TextServicesSettings settings) {
    list.clear();
    map.clear();
    final PackageManager pm = context.getPackageManager();
    // Note: We do not specify PackageManager.MATCH_ENCRYPTION_* flags here because the default
    // behavior of PackageManager is exactly what we want.  It by default picks up appropriate
    // services depending on the unlock state for the specified user.
    final List<ResolveInfo> services = pm.queryIntentServicesAsUser(new Intent(SpellCheckerService.SERVICE_INTERFACE), PackageManager.GET_META_DATA, settings.getCurrentUserId());
    final int N = services.size();
    for (int i = 0; i < N; ++i) {
        final ResolveInfo ri = services.get(i);
        final ServiceInfo si = ri.serviceInfo;
        final ComponentName compName = new ComponentName(si.packageName, si.name);
        if (!android.Manifest.permission.BIND_TEXT_SERVICE.equals(si.permission)) {
            Slog.w(TAG, "Skipping text service " + compName + ": it does not require the permission " + android.Manifest.permission.BIND_TEXT_SERVICE);
            continue;
        }
        if (DBG)
            Slog.d(TAG, "Add: " + compName);
        try {
            final SpellCheckerInfo sci = new SpellCheckerInfo(context, ri);
            if (sci.getSubtypeCount() <= 0) {
                Slog.w(TAG, "Skipping text service " + compName + ": it does not contain subtypes.");
                continue;
            }
            list.add(sci);
            map.put(sci.getId(), sci);
        } catch (XmlPullParserException e) {
            Slog.w(TAG, "Unable to load the spell checker " + compName, e);
        } catch (IOException e) {
            Slog.w(TAG, "Unable to load the spell checker " + compName, e);
        }
    }
    if (DBG) {
        Slog.d(TAG, "buildSpellCheckerMapLocked: " + list.size() + "," + map.size());
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) PackageManager(android.content.pm.PackageManager) Intent(android.content.Intent) ComponentName(android.content.ComponentName) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 89 with ComponentName

use of android.content.ComponentName in project platform_frameworks_base by android.

the class ServiceWatcher method bindBestPackageLocked.

/**
     * Searches and binds to the best package, or do nothing if the best package
     * is already bound, unless force rebinding is requested.
     *
     * @param justCheckThisPackage Only consider this package, or consider all
     *            packages if it is {@code null}.
     * @param forceRebind Force a rebinding to the best package if it's already
     *            bound.
     * @returns {@code true} if a valid package was found to bind to.
     */
private boolean bindBestPackageLocked(String justCheckThisPackage, boolean forceRebind) {
    Intent intent = new Intent(mAction);
    if (justCheckThisPackage != null) {
        intent.setPackage(justCheckThisPackage);
    }
    final List<ResolveInfo> rInfos = mPm.queryIntentServicesAsUser(intent, PackageManager.GET_META_DATA | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, mCurrentUserId);
    int bestVersion = Integer.MIN_VALUE;
    ComponentName bestComponent = null;
    boolean bestIsMultiuser = false;
    if (rInfos != null) {
        for (ResolveInfo rInfo : rInfos) {
            final ComponentName component = rInfo.serviceInfo.getComponentName();
            final String packageName = component.getPackageName();
            // check signature
            try {
                PackageInfo pInfo;
                pInfo = mPm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES | PackageManager.MATCH_DEBUG_TRIAGED_MISSING);
                if (!isSignatureMatch(pInfo.signatures)) {
                    Log.w(mTag, packageName + " resolves service " + mAction + ", but has wrong signature, ignoring");
                    continue;
                }
            } catch (NameNotFoundException e) {
                Log.wtf(mTag, e);
                continue;
            }
            // check metadata
            int version = Integer.MIN_VALUE;
            boolean isMultiuser = false;
            if (rInfo.serviceInfo.metaData != null) {
                version = rInfo.serviceInfo.metaData.getInt(EXTRA_SERVICE_VERSION, Integer.MIN_VALUE);
                isMultiuser = rInfo.serviceInfo.metaData.getBoolean(EXTRA_SERVICE_IS_MULTIUSER);
            }
            if (version > bestVersion) {
                bestVersion = version;
                bestComponent = component;
                bestIsMultiuser = isMultiuser;
            }
        }
        if (D) {
            Log.d(mTag, String.format("bindBestPackage for %s : %s found %d, %s", mAction, (justCheckThisPackage == null ? "" : "(" + justCheckThisPackage + ") "), rInfos.size(), (bestComponent == null ? "no new best component" : "new best component: " + bestComponent)));
        }
    } else {
        if (D)
            Log.d(mTag, "Unable to query intent services for action: " + mAction);
    }
    if (bestComponent == null) {
        Slog.w(mTag, "Odd, no component found for service " + mAction);
        unbindLocked();
        return false;
    }
    final int userId = bestIsMultiuser ? UserHandle.USER_SYSTEM : mCurrentUserId;
    final boolean alreadyBound = Objects.equals(bestComponent, mBoundComponent) && bestVersion == mBoundVersion && userId == mBoundUserId;
    if (forceRebind || !alreadyBound) {
        unbindLocked();
        bindToPackageLocked(bestComponent, bestVersion, userId);
    }
    return true;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

Example 90 with ComponentName

use of android.content.ComponentName in project platform_frameworks_base by android.

the class Telecom method getPhoneAccountHandleFromArgs.

private PhoneAccountHandle getPhoneAccountHandleFromArgs() throws RemoteException {
    final ComponentName component = parseComponentName(nextArgRequired());
    final String accountId = nextArgRequired();
    final String userSnInStr = nextArgRequired();
    UserHandle userHandle;
    try {
        final int userSn = Integer.parseInt(userSnInStr);
        userHandle = UserHandle.of(mUserManager.getUserHandle(userSn));
    } catch (NumberFormatException ex) {
        throw new IllegalArgumentException("Invalid user serial number " + userSnInStr);
    }
    return new PhoneAccountHandle(component, accountId, userHandle);
}
Also used : PhoneAccountHandle(android.telecom.PhoneAccountHandle) UserHandle(android.os.UserHandle) ComponentName(android.content.ComponentName)

Aggregations

ComponentName (android.content.ComponentName)2548 Intent (android.content.Intent)959 ResolveInfo (android.content.pm.ResolveInfo)375 RemoteException (android.os.RemoteException)317 PackageManager (android.content.pm.PackageManager)269 PendingIntent (android.app.PendingIntent)252 ActivityInfo (android.content.pm.ActivityInfo)243 ArrayList (java.util.ArrayList)242 ShortcutInfo (android.content.pm.ShortcutInfo)152 Point (android.graphics.Point)145 Bundle (android.os.Bundle)139 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)132 IBinder (android.os.IBinder)128 IOException (java.io.IOException)125 ServiceConnection (android.content.ServiceConnection)96 ServiceInfo (android.content.pm.ServiceInfo)96 UserHandle (android.os.UserHandle)86 ArraySet (android.util.ArraySet)73 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)69 Uri (android.net.Uri)68