Java Code Examples for android.content.ComponentName#flattenToString()

The following examples show how to use android.content.ComponentName#flattenToString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MediaSessionService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public void rememberMediaButtonReceiverLocked(MediaSessionRecord record) {
    PendingIntent receiver = record.getMediaButtonReceiver();
    mLastMediaButtonReceiver = receiver;
    mRestoredMediaButtonReceiver = null;
    String componentName = "";
    if (receiver != null) {
        ComponentName component = receiver.getIntent().getComponent();
        if (component != null
                && record.getPackageName().equals(component.getPackageName())) {
            componentName = component.flattenToString();
        }
    }
    Settings.Secure.putStringForUser(mContentResolver,
            Settings.System.MEDIA_BUTTON_RECEIVER,
            componentName + COMPONENT_NAME_USER_ID_DELIM + record.getUserId(),
            mFullUserId);
}
 
Example 2
Source File: ViewDebugHelperService.java    From ViewDebugHelper with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        event.getWindowId();
        ComponentName componentName = new ComponentName(event.getPackageName().toString(), event.getClassName().toString());
        ActivityInfo activityInfo = ActivityHelper.tryGetActivity(this, componentName);
        boolean isActivity = activityInfo != null;
        if (isActivity) {
            String activityName = componentName.flattenToString();
            log("CurrentActivity" + activityName);
            ViewDebugHelperApplication.getInstance().setLastTopActivityName(activityName);
            ActivityStackManager.getInstance().offer(activityName);
        }
    }
}
 
Example 3
Source File: DesktopIconInfoTest.java    From Taskbar with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    context = ApplicationProvider.getApplicationContext();
    packageName = context.getPackageName();
    Drawable icon = context.getResources().getDrawable(R.drawable.tb_apps);
    ComponentName componentName = new ComponentName(context, MainActivity.class);
    appEntry =
            new AppEntry(
                    packageName,
                    componentName.flattenToString(),
                    packageName,
                    icon,
                    false
            );
    desktopIconInfo = new DesktopIconInfo(defaultColumn, defaultRow, appEntry);
}
 
Example 4
Source File: LauncherModel.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if the shortcuts already exists in the database. we identify
 * a shortcut by the component name of the intent.
 */
static boolean appWasRestored(Context context, Intent intent) {
	final ContentResolver cr = context.getContentResolver();
	final ComponentName component = intent.getComponent();
	if (component == null) {
		return false;
	}
	String componentName = component.flattenToString();
	final String where = "intent glob \"*component=" + componentName
			+ "*\" and restored = 1";
	Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI,
			new String[] { "intent", "restored" }, where, null, null);
	boolean result = false;
	try {
		result = c.moveToFirst();
	} finally {
		c.close();
	}

	return result;
}
 
Example 5
Source File: StringFilter.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public String getValue(ComponentName resolvedComponent, Intent intent,
        String resolvedType) {
    if (resolvedComponent != null) {
        return resolvedComponent.flattenToString();
    }
    return null;
}
 
Example 6
Source File: AppEntryTest.java    From Taskbar with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    context = ApplicationProvider.getApplicationContext();
    componentName = new ComponentName(context, MainActivity.class);
    icon = context.getResources().getDrawable(R.drawable.tb_apps);
    appEntry = new AppEntry(
            context.getPackageName(),
            componentName.flattenToString(),
            context.getPackageName(),
            icon,
            true
    );
}
 
Example 7
Source File: DevicePluginManager.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * リクエストに含まれるセッションキーを変換する.
 * <p>
 * セッションキーにデバイスプラグインIDとreceiverを追加する。
 * 下記のように、分解できるようになっている。
 *
 * 【セッションキー.デバイスプラグインID@receiver】
 * </p>
 * @param request リクエスト
 * @param plugin  デバイスプラグイン
 */
public void appendPluginIdToSessionKey(final Intent request, final DevicePlugin plugin) {
    String sessionKey = request.getStringExtra(DConnectMessage.EXTRA_SESSION_KEY);
    if (plugin != null && sessionKey != null) {
        sessionKey = sessionKey + DConnectConst.SEPARATOR + plugin.getPluginId();
        ComponentName receiver = (ComponentName) request.getExtras().get(DConnectMessage.EXTRA_RECEIVER);
        if (receiver != null) {
            sessionKey = sessionKey + DConnectConst.SEPARATOR_SESSION + receiver.flattenToString();
        }
        request.putExtra(DConnectMessage.EXTRA_SESSION_KEY, sessionKey);
    }
}
 
Example 8
Source File: Folder.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
private String getComponentString() {
    int size = mItemsInReadingOrder.size();
    String components = "";
    for (int i = 0; i < size; i++) {
        View v = mItemsInReadingOrder.get(i);
        Object tag = v.getTag();
        if (tag instanceof ShortcutInfo) {
            ComponentName componentName = ((ShortcutInfo) tag).getIntent().getComponent();
            components += componentName.flattenToString() + "|";
        }
    }

    return components;
}
 
Example 9
Source File: WallpaperManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void processDisconnect(final ServiceConnection connection) {
    synchronized (mLock) {
        // The wallpaper disappeared.  If this isn't a system-default one, track
        // crashes and fall back to default if it continues to misbehave.
        if (connection == mWallpaper.connection) {
            final ComponentName wpService = mWallpaper.wallpaperComponent;
            if (!mWallpaper.wallpaperUpdating
                    && mWallpaper.userId == mCurrentUserId
                    && !Objects.equals(mDefaultWallpaperComponent, wpService)
                    && !Objects.equals(mImageWallpaper, wpService)) {
                // There is a race condition which causes
                // {@link #mWallpaper.wallpaperUpdating} to be false even if it is
                // currently updating since the broadcast notifying us is async.
                // This race is overcome by the general rule that we only reset the
                // wallpaper if its service was shut down twice
                // during {@link #MIN_WALLPAPER_CRASH_TIME} millis.
                if (mWallpaper.lastDiedTime != 0
                        && mWallpaper.lastDiedTime + MIN_WALLPAPER_CRASH_TIME
                        > SystemClock.uptimeMillis()) {
                    Slog.w(TAG, "Reverting to built-in wallpaper!");
                    clearWallpaperLocked(true, FLAG_SYSTEM, mWallpaper.userId, null);
                } else {
                    mWallpaper.lastDiedTime = SystemClock.uptimeMillis();

                    clearWallpaperComponentLocked(mWallpaper);
                    if (bindWallpaperComponentLocked(
                            wpService, false, false, mWallpaper, null)) {
                        mWallpaper.connection.scheduleTimeoutLocked();
                    } else {
                        Slog.w(TAG, "Reverting to built-in wallpaper!");
                        clearWallpaperLocked(true, FLAG_SYSTEM, mWallpaper.userId, null);
                    }
                }
                final String flattened = wpService.flattenToString();
                EventLog.writeEvent(EventLogTags.WP_WALLPAPER_CRASHED,
                        flattened.substring(0, Math.min(flattened.length(),
                                MAX_WALLPAPER_COMPONENT_LOG_LENGTH)));
            }
        } else {
            if (DEBUG_LIVE) {
                Slog.i(TAG, "Wallpaper changed during disconnect tracking; ignoring");
            }
        }
    }
}
 
Example 10
Source File: SettingsStringUtil.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
protected String itemToString(ComponentName item) {
    return item.flattenToString();
}
 
Example 11
Source File: UTest.java    From Taskbar with Apache License 2.0 4 votes vote down vote up
@Test
public void testIsAccessibilityServiceEnabled() {
    String enabledServices =
            Settings.Secure.getString(
                    context.getContentResolver(),
                    Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES
            );
    ComponentName componentName = new ComponentName(context, PowerMenuService.class);
    String flattenString = componentName.flattenToString();
    String flattenShortString = componentName.flattenToShortString();
    String newEnabledService =
            enabledServices == null ?
                    "" :
                    enabledServices
                            .replaceAll(":" + flattenString, "")
                            .replaceAll(":" + flattenShortString, "")
                            .replaceAll(flattenString, "")
                            .replaceAll(flattenShortString, "");
    Settings.Secure.putString(
            context.getContentResolver(),
            Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
            newEnabledService
    );
    assertFalse(U.isAccessibilityServiceEnabled(context));
    Settings.Secure.putString(
            context.getContentResolver(),
            Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
            newEnabledService + ":" + flattenString
    );
    assertTrue(U.isAccessibilityServiceEnabled(context));
    Settings.Secure.putString(
            context.getContentResolver(),
            Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
            newEnabledService + ":" + flattenShortString
    );
    assertTrue(U.isAccessibilityServiceEnabled(context));
    Settings.Secure.putString(
            context.getContentResolver(),
            Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
            enabledServices
    );
}
 
Example 12
Source File: CumulusChannel.java    From CumulusTV with MIT License 4 votes vote down vote up
public Builder setPluginSource(@NonNull ComponentName pluginComponent) {
    if (pluginComponent != null) {
        cumulusChannel.pluginSource = pluginComponent.flattenToString();
    }
    return this;
}
 
Example 13
Source File: XposedMod.java    From ActivityForceNewTask with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
    if (!lpparam.packageName.equals("android"))
        return;

    XC_MethodHook hook = new XC_MethodHook() {
        @Override
        protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            settingsHelper.reload();
            if (settingsHelper.isModDisabled())
                return;
            Intent intent = (Intent) XposedHelpers.getObjectField(param.thisObject, "intent");

            // The launching app does not expect data back. It's safe to run the activity in a
            // new task.
            int requestCode = getIntField(param.thisObject, "requestCode");
            if (requestCode != -1)
                return;

            // The intent already has FLAG_ACTIVITY_NEW_TASK set, no need to do anything.
            if ((intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) == Intent.FLAG_ACTIVITY_NEW_TASK)
                return;

            String intentAction = intent.getAction();
            // If the intent is not a known safe intent (as in, the launching app does not expect
            // data back, so it's safe to run in a new task,) ignore it straight away.
            if (intentAction == null)
                return;

            // If the app is launching one of its own activities, we shouldn't open it in a new task.
            int uid = ((ActivityInfo) getObjectField(param.thisObject, "info")).applicationInfo.uid;
            if (getIntField(param.thisObject, "launchedFromUid") == uid)
                return;

            ComponentName componentName = (ComponentName) getObjectField(param.thisObject, "realActivity");
            String componentNameString = componentName.flattenToString();
            // Log if necessary.
            if (settingsHelper.isLogEnabled()) {
                // Get context
                Context context = AndroidAppHelper.currentApplication();

                if (context != null)
                    context.sendBroadcast(new Intent(Common.INTENT_LOG).putExtra(Common.INTENT_COMPONENT_EXTRA, componentNameString));
                else
                    XposedBridge.log("activityforcenewtask: couldn't get context.");
                XposedBridge.log("activityforcenewtask: componentString: " + componentNameString);
            }

            // If the blacklist is used and the component is in the blacklist, or if the
            // whitelist is used and the component isn't whitelisted, we shouldn't modify
            // the intent's flags.
            boolean isListed = settingsHelper.isListed(componentNameString);
            String listType = settingsHelper.getListType();
            if ((listType.equals(Common.PREF_BLACKLIST) && isListed) ||
                    (listType.equals(Common.PREF_WHITELIST) && !isListed))
                return;

            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
    };

    Class ActivityRecord = findClass("com.android.server.am.ActivityRecord", lpparam.classLoader);
    XposedBridge.hookAllConstructors(ActivityRecord, hook);
}