Java Code Examples for android.content.pm.ActivityInfo#LAUNCH_SINGLE_INSTANCE

The following examples show how to use android.content.pm.ActivityInfo#LAUNCH_SINGLE_INSTANCE . 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: FixedActivityCache.java    From Phantom with Apache License 2.0 6 votes vote down vote up
void save(FixedActivity fixedActivity, int launchMode) {
    Set<String> fixedActivities = null;
    String tag = null;

    if (launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {
        fixedActivities = mSingleTopFixedActivities;
        tag = TAG_SINGLE_TOP;
    } else if (launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
        fixedActivities = mSingleInstanceFixedActivities;
        tag = TAG_SINGLE_INSTANCE;
    } else if (launchMode == ActivityInfo.LAUNCH_SINGLE_TASK) {
        fixedActivities = mSingleTaskFixedActivities;
        tag = TAG_SINGLE_TASK;
    }

    if (null != fixedActivities) {
        int size = fixedActivities.size();
        fixedActivities.add(fixedActivity.toString());
        if (fixedActivities.size() > size) {
            mSharedPreferences.edit()
                    .putStringSet(tag, fixedActivities)
                    .apply();
        }
    }
}
 
Example 2
Source File: U.java    From Taskbar with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.N)
public static void applyOpenInNewWindow(Context context, Intent intent) {
    if(!isFreeformModeEnabled(context)) return;

    intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);

    ActivityInfo activityInfo = intent.resolveActivityInfo(context.getPackageManager(), 0);
    if(activityInfo != null) {
        switch(activityInfo.launchMode) {
            case ActivityInfo.LAUNCH_SINGLE_TASK:
            case ActivityInfo.LAUNCH_SINGLE_INSTANCE:
                intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
                break;
        }
    }
}
 
Example 3
Source File: RunningActivities.java    From DroidPlugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void onActivtyDestory(Activity activity) {
    synchronized (mRunningActivityList) {
        RunningActivityRecord value = mRunningActivityList.remove(activity);
        if (value != null) {
            ActivityInfo targetActivityInfo = value.targetActivityInfo;
            if (targetActivityInfo.launchMode == ActivityInfo.LAUNCH_MULTIPLE) {
                mRunningSingleStandardActivityList.remove(value.index);
            } else if (targetActivityInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {
                mRunningSingleTopActivityList.remove(value.index);
            } else if (targetActivityInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK) {
                mRunningSingleTaskActivityList.remove(value.index);
            } else if (targetActivityInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
                mRunningSingleInstanceActivityList.remove(value.index);
            }
        }
    }
}
 
Example 4
Source File: LaunchModeManager.java    From Phantom with Apache License 2.0 5 votes vote down vote up
private String launchModeToString(int launchMode) {
    String mode = "standard";
    if (launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {
        mode = "singleTop";
    } else if (launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
        mode = "singleInstance";
    } else if (launchMode == ActivityInfo.LAUNCH_SINGLE_TASK) {
        mode = "singleTask";
    }

    return mode;
}
 
Example 5
Source File: LaunchModeStates.java    From springreplugin with Apache License 2.0 5 votes vote down vote up
/**
 * 获取 launchMode 对应的前缀
 */
private static String getLaunchModeInfix(int launchMode) {
    switch (launchMode) {
        case ActivityInfo.LAUNCH_SINGLE_TOP:
            return "STP";
        case ActivityInfo.LAUNCH_SINGLE_TASK:
            return "ST";
        case ActivityInfo.LAUNCH_SINGLE_INSTANCE:
            return "SI";
        default:
            return "NR";
    }
}
 
Example 6
Source File: Utils.java    From Android-Applications-Info with Apache License 2.0 5 votes vote down vote up
public static String getLaunchMode(int mode) {
    switch (mode) {
        case ActivityInfo.LAUNCH_MULTIPLE:
            return "Multiple";
        case ActivityInfo.LAUNCH_SINGLE_INSTANCE:
            return "Single instance";
        case ActivityInfo.LAUNCH_SINGLE_TASK:
            return "Single task";
        case ActivityInfo.LAUNCH_SINGLE_TOP:
            return "Single top";
        default:
            return "null";
    }
}
 
Example 7
Source File: RunningActivities.java    From DroidPlugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void onActivtyCreate(Activity activity, ActivityInfo targetActivityInfo, ActivityInfo stubActivityInfo) {
    synchronized (mRunningActivityList) {
        RunningActivityRecord value = new RunningActivityRecord(activity, targetActivityInfo, stubActivityInfo, findMaxIndex() + 1);
        mRunningActivityList.put(activity, value);
        if (targetActivityInfo.launchMode == ActivityInfo.LAUNCH_MULTIPLE) {
            mRunningSingleStandardActivityList.put(value.index, value);
        } else if (targetActivityInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {
            mRunningSingleTopActivityList.put(value.index, value);
        } else if (targetActivityInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK) {
            mRunningSingleTaskActivityList.put(value.index, value);
        } else if (targetActivityInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
            mRunningSingleInstanceActivityList.put(value.index, value);
        }
    }
}
 
Example 8
Source File: RunningActivities.java    From DroidPlugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void beforeStartActivity() {
    synchronized (mRunningActivityList) {
        for (RunningActivityRecord record : mRunningActivityList.values()) {
            if (record.stubActivityInfo.launchMode == ActivityInfo.LAUNCH_MULTIPLE) {
                continue;
            } else if (record.stubActivityInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {
                doFinshIt(mRunningSingleTopActivityList);
            } else if (record.stubActivityInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK) {
                doFinshIt(mRunningSingleTopActivityList);
            } else if (record.stubActivityInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
                doFinshIt(mRunningSingleTopActivityList);
            }
        }
    }
}
 
Example 9
Source File: LaunchModeManager.java    From Phantom with Apache License 2.0 4 votes vote down vote up
/**
 * 获取一个占位activity
 *
 * @param pluginActivity 插件activity
 * @param launchMode     插件activity启动模式
 * @param isFixed        是否建立固定映射关系
 * @return 占位activity
 * @throws ProxyActivityLessException 占位activity不够异常
 */
private String findActivity(String pluginActivity, int launchMode, boolean isFixed)
        throws ProxyActivityLessException {

    String activity = MODE_STANDARD;
    ActivityPool pool = null;

    switch (launchMode) {
        case ActivityInfo.LAUNCH_MULTIPLE:
            final PhantomCore phantomCore = PhantomCore.getInstance();
            final ComponentName componentName = ComponentName.unflattenFromString(pluginActivity);
            if (componentName != null) {
                final ActivityInfo ai = phantomCore.findActivityInfo(componentName);
                final PluginInfo pluginInfo = phantomCore.findPluginInfoByActivityName(componentName);
                final int themeResourceId = ai == null ? -1 : ai.getThemeResource();
                if (themeResourceId != -1 && pluginInfo != null) {
                    final Resources resources = pluginInfo.getPluginResources();
                    if (resources != null) {
                        final Resources.Theme theme = resources.newTheme();
                        theme.applyStyle(themeResourceId, true);
                        final TypedArray sa = theme.obtainStyledAttributes(
                                new int[]{android.R.attr.windowIsTranslucent});
                        final boolean translucent = sa.getBoolean(0, false);
                        sa.recycle();
                        activity = translucent ? MODE_STANDARD_TRANSLUCENT : MODE_STANDARD;
                    }
                }
            }
            break;
        case ActivityInfo.LAUNCH_SINGLE_TOP:
            pool = mSingleTopPool;
            break;
        case ActivityInfo.LAUNCH_SINGLE_INSTANCE:
            pool = mSingleInstancePool;
            break;
        case ActivityInfo.LAUNCH_SINGLE_TASK:
            pool = mSingleTaskPool;
            break;
        default:
            break;
    }

    if (null != pool) {
        activity = isFixed ? pool.resolveFixedActivity(pluginActivity) : pool.resolveActivity(pluginActivity);
    }

    String msg = String.format("resolve %s Activity for %s proxy is %s, fixed is %s",
            launchModeToString(launchMode), pluginActivity, activity, isFixed);
    VLog.d(msg);
    if (null == activity) {
        //占位activity不够使用, 这种情况不做处理,宿主提供足够的占位activity
        //这里不做主动回收,如果做主动回收可能会使程序正常执行流程发送改变
        ProxyActivityLessException pae = new ProxyActivityLessException(msg);
        LogReporter.reportException(pae, null);
        mCache.clean();
        throw pae;
    }

    return activity;
}
 
Example 10
Source File: BaseDetectionEngine.java    From android-overlay-protection with Apache License 2.0 4 votes vote down vote up
@Override
public void handleEvent(AccessibilityEvent event) {
    // Avoid processing events when screen is locked
    if (_keyguardManager != null) {
        boolean locked = _keyguardManager.inKeyguardRestrictedInputMode();
        if (locked) {
            Log.i(TAG, "Screen locked, skipping overlay check!");
            return;
        }
    }

    Log.d(TAG, String.format("New event %s", event.toString()));
    _eventCounter.newEvent();
    _notifyService.updateNotificationCount(_eventCounter.getLastMinuteEventCount());
    if (_resultReceiver != null) {
        Bundle bundle = new Bundle();
        bundle.putLong("eventCount", _eventCounter.getLastMinuteEventCount());
        _resultReceiver.send(ServiceCommunication.MSG_EVENT_COUNT_UPDATE, bundle);
    }


    // When overlay is detected avoid performing useless computation
    if (_overlayState.isHasOverlay() || _overlayState.isPendingUninstall())
        return;

    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        if (event.getPackageName() == null)
            return;

        String eventPackage = event.getPackageName().toString();
        ComponentName componentName = new ComponentName(
                eventPackage,
                event.getClassName().toString()
        );
        ActivityInfo activityInfo = tryGetActivity(componentName);
        boolean isActivity = activityInfo != null;
        if (isActivity) {
            LogPrinter logPrinter = new LogPrinter(Log.DEBUG, TAG);
            activityInfo.dump(logPrinter, "");
        }
        String className = event.getClassName().toString();

        // Perform detection
        boolean parentAvailable = event.getSource() != null ? event.getSource().getParent() != null : false;

        Log.d(TAG, String.format("Collected info isActivity %s, parentAvailable: %s", String.valueOf(isActivity), String.valueOf(parentAvailable)));

        if (_overlayState.getIgnoreOncePackage().equals(eventPackage)) {
            Log.d(TAG, String.format("Package %s ignored once", eventPackage));
        } else if (eventPackage.equals(previousEventPackage)) {
            Log.d(TAG, String.format("Last two event have the same package %s, skipping check!", eventPackage));
        } else if (_layoutClasses.contains(className) && !isActivity && !parentAvailable) {
            Log.d(TAG, String.format("Detected suspicious class %s without activity and parent for process %s, checking whitelist", className, eventPackage));
            if (!checkWhitelistHit(eventPackage)) {
                Log.d(TAG, "No whitelist entry found");
                if (checkSuspectedApps(eventPackage)) {
                    Log.d(TAG, String.format("******* VIEW OVERLAY DETECTED!!!"));
                    _overlayState.setOffender(eventPackage);
                    _overlayState.setProcess(_currentProcess);
                    _notifyService.processOverlayState(_overlayState);
                }
            } else {
                Log.d(TAG, "Whitelist hit skipping!");
            }
        } else if (isActivity && activityInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE && !parentAvailable) {
            Log.d(TAG, String.format("Detected suspicious activity %s with single instance flag, checking whitelist", activityInfo.packageName));
            if (!checkWhitelistHit(eventPackage)) {
                Log.d(TAG, "No whitelist entry found");
                if (checkSuspectedApps(eventPackage)) {
                    Log.d(TAG, String.format("******* ACTIVITY OVERLAY DETECTED!!!"));
                    _overlayState.setOffender(eventPackage);
                    _overlayState.setProcess(_currentProcess);
                    _notifyService.processOverlayState(_overlayState);
                }
            } else {
                Log.d(TAG, "Whitelist hit skipping!");
            }
        }
        previousEventPackage = eventPackage;
    }
}
 
Example 11
Source File: PluginStubBinding.java    From PluginLoader with Apache License 2.0 3 votes vote down vote up
private static void initPool() {
	if (isPoolInited) {
		return;
	}

	Intent launchModeIntent = new Intent();
	launchModeIntent.setAction(ACTION_LAUNCH_MODE);
	launchModeIntent.setPackage(PluginLoader.getApplicatoin().getPackageName());

	List<ResolveInfo> list = PluginLoader.getApplicatoin().getPackageManager().queryIntentActivities(launchModeIntent, PackageManager.MATCH_DEFAULT_ONLY);

	if (list != null && list.size() >0) {
		for (ResolveInfo resolveInfo:
				list) {
			if (resolveInfo.activityInfo.name.startsWith(STUB_ACTIVITY_PRE)) {

				if (resolveInfo.activityInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK) {

					singleTaskMapping.put(resolveInfo.activityInfo.name, null);

				} else if (resolveInfo.activityInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {

					singleTopMapping.put(resolveInfo.activityInfo.name, null);

				} else if (resolveInfo.activityInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {

					singleInstanceMapping.put(resolveInfo.activityInfo.name, null);

				}

			}
		}
	}

	isPoolInited = true;
}
 
Example 12
Source File: PluginStubBinding.java    From PluginLoader with Apache License 2.0 2 votes vote down vote up
public static String bindLaunchModeStubActivity(String pluginActivityClassName, int launchMode) {

		initPool();

		String stubActivityName = null;

		Iterator<Map.Entry<String, String>> itr = null;

		if (launchMode == ActivityInfo.LAUNCH_SINGLE_TASK) {

			itr = singleTaskMapping.entrySet().iterator();

		} else if (launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {

			itr = singleTopMapping.entrySet().iterator();

		} else if (launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {

			itr = singleInstanceMapping.entrySet().iterator();

		}

		if (itr != null) {

			String idleStubActivityName = null;

			while (itr.hasNext()) {
				Map.Entry<String, String> entry = itr.next();
				if (entry.getValue() == null) {
					if (idleStubActivityName == null) {
						idleStubActivityName = entry.getKey();
					}
				} else if (pluginActivityClassName.equals(entry.getValue())) {
					return entry.getKey();
				}
			}

			//没有绑定到StubActivity,而且还有空余的stubActivity,进行绑定
			if (idleStubActivityName != null) {
				singleTaskMapping.put(idleStubActivityName, pluginActivityClassName);
				return idleStubActivityName;
			}

		}

		//绑定失败
		return PluginStubActivity.class.getName();
	}
 
Example 13
Source File: StubActivityMappingProcessor.java    From Android-Plugin-Framework with MIT License 2 votes vote down vote up
private static void loadStubActivity() {
    Intent launchModeIntent = new Intent();
    launchModeIntent.setAction(buildDefaultAction());
    launchModeIntent.setPackage(FairyGlobal.getHostApplication().getPackageName());

    List<ResolveInfo> list = FairyGlobal.getHostApplication().getPackageManager().queryIntentActivities(launchModeIntent, PackageManager.MATCH_DEFAULT_ONLY);

    if (list != null && list.size() >0) {
        for (ResolveInfo resolveInfo:
                list) {
            if (resolveInfo.activityInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK) {

                singleTaskActivityMapping.put(resolveInfo.activityInfo.name, null);

            } else if (resolveInfo.activityInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {

                singleTopActivityMapping.put(resolveInfo.activityInfo.name, null);

            } else if (resolveInfo.activityInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {

                singleInstanceActivityMapping.put(resolveInfo.activityInfo.name, null);

            } else if (resolveInfo.activityInfo.launchMode == ActivityInfo.LAUNCH_MULTIPLE) {

                if (resolveInfo.activityInfo.theme == android.R.style.Theme_Translucent) {

                    standardActivityTranslucentMapping.put(resolveInfo.activityInfo.name, null);

                } else if (resolveInfo.activityInfo.screenOrientation == SCREEN_ORIENTATION_LANDSCAPE) {

                    standardLandspaceActivity = resolveInfo.activityInfo.name;

                } else {

                    standardActivityMapping.put(resolveInfo.activityInfo.name, null);

                }
            }

        }
    }

}