Search in sources :

Example 1 with ActivityClientRecord

use of com.lody.virtual.client.ipc.ActivityClientRecord in project VirtualApp by asLody.

the class StartActivity method call.

@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
    int intentIndex = ArrayUtils.indexOfObject(args, Intent.class, 1);
    if (intentIndex < 0) {
        return ActivityManagerCompat.START_INTENT_NOT_RESOLVED;
    }
    int resultToIndex = ArrayUtils.indexOfObject(args, IBinder.class, 2);
    String resolvedType = (String) args[intentIndex + 1];
    Intent intent = (Intent) args[intentIndex];
    intent.setDataAndType(intent.getData(), resolvedType);
    IBinder resultTo = resultToIndex >= 0 ? (IBinder) args[resultToIndex] : null;
    int userId = VUserHandle.myUserId();
    if (ComponentUtils.isStubComponent(intent)) {
        return method.invoke(who, args);
    }
    if (Intent.ACTION_INSTALL_PACKAGE.equals(intent.getAction()) || (Intent.ACTION_VIEW.equals(intent.getAction()) && "application/vnd.android.package-archive".equals(intent.getType()))) {
        if (handleInstallRequest(intent)) {
            return 0;
        }
    } else if ((Intent.ACTION_UNINSTALL_PACKAGE.equals(intent.getAction()) || Intent.ACTION_DELETE.equals(intent.getAction())) && "package".equals(intent.getScheme())) {
        if (handleUninstallRequest(intent)) {
            return 0;
        }
    }
    String resultWho = null;
    int requestCode = 0;
    Bundle options = ArrayUtils.getFirst(args, Bundle.class);
    if (resultTo != null) {
        resultWho = (String) args[resultToIndex + 1];
        requestCode = (int) args[resultToIndex + 2];
    }
    // chooser
    if (ChooserActivity.check(intent)) {
        intent.setComponent(new ComponentName(getHostContext(), ChooserActivity.class));
        intent.putExtra(Constants.EXTRA_USER_HANDLE, userId);
        intent.putExtra(ChooserActivity.EXTRA_DATA, options);
        intent.putExtra(ChooserActivity.EXTRA_WHO, resultWho);
        intent.putExtra(ChooserActivity.EXTRA_REQUEST_CODE, requestCode);
        return method.invoke(who, args);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        args[intentIndex - 1] = getHostPkg();
    }
    ActivityInfo activityInfo = VirtualCore.get().resolveActivityInfo(intent, userId);
    if (activityInfo == null) {
        return method.invoke(who, args);
    }
    int res = VActivityManager.get().startActivity(intent, activityInfo, resultTo, options, resultWho, requestCode, VUserHandle.myUserId());
    if (res != 0 && resultTo != null && requestCode > 0) {
        VActivityManager.get().sendActivityResult(resultTo, resultWho, requestCode);
    }
    if (resultTo != null) {
        ActivityClientRecord r = VActivityManager.get().getActivityRecord(resultTo);
        if (r != null && r.activity != null) {
            try {
                TypedValue out = new TypedValue();
                Resources.Theme theme = r.activity.getResources().newTheme();
                theme.applyStyle(activityInfo.getThemeResource(), true);
                if (theme.resolveAttribute(android.R.attr.windowAnimationStyle, out, true)) {
                    TypedArray array = theme.obtainStyledAttributes(out.data, new int[] { android.R.attr.activityOpenEnterAnimation, android.R.attr.activityOpenExitAnimation });
                    r.activity.overridePendingTransition(array.getResourceId(0, 0), array.getResourceId(1, 0));
                    array.recycle();
                }
            } catch (Throwable e) {
            // Ignore
            }
        }
    }
    return res;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) Bundle(android.os.Bundle) ActivityClientRecord(com.lody.virtual.client.ipc.ActivityClientRecord) Intent(android.content.Intent) IBinder(android.os.IBinder) TypedArray(android.content.res.TypedArray) ChooserActivity(com.lody.virtual.client.stub.ChooserActivity) ComponentName(android.content.ComponentName) Resources(android.content.res.Resources) TypedValue(android.util.TypedValue)

Example 2 with ActivityClientRecord

use of com.lody.virtual.client.ipc.ActivityClientRecord in project VirtualApp by asLody.

the class AppInstrumentation method callActivityOnCreate.

@Override
public void callActivityOnCreate(Activity activity, Bundle icicle) {
    VirtualCore.get().getComponentDelegate().beforeActivityCreate(activity);
    IBinder token = mirror.android.app.Activity.mToken.get(activity);
    ActivityClientRecord r = VActivityManager.get().getActivityRecord(token);
    if (r != null) {
        r.activity = activity;
    }
    ContextFixer.fixContext(activity);
    ActivityFixer.fixActivity(activity);
    ActivityInfo info = null;
    if (r != null) {
        info = r.info;
    }
    if (info != null) {
        if (info.theme != 0) {
            activity.setTheme(info.theme);
        }
        if (activity.getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED && info.screenOrientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
            activity.setRequestedOrientation(info.screenOrientation);
        }
    }
    super.callActivityOnCreate(activity, icicle);
    VirtualCore.get().getComponentDelegate().afterActivityCreate(activity);
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) IBinder(android.os.IBinder) ActivityClientRecord(com.lody.virtual.client.ipc.ActivityClientRecord)

Example 3 with ActivityClientRecord

use of com.lody.virtual.client.ipc.ActivityClientRecord in project VirtualApp by asLody.

the class FinishActivity method afterCall.

@Override
public Object afterCall(Object who, Method method, Object[] args, Object result) throws Throwable {
    IBinder token = (IBinder) args[0];
    ActivityClientRecord r = VActivityManager.get().getActivityRecord(token);
    boolean taskRemoved = VActivityManager.get().onActivityDestroy(token);
    if (!taskRemoved && r != null && r.activity != null && r.info.getThemeResource() != 0) {
        try {
            TypedValue out = new TypedValue();
            Resources.Theme theme = r.activity.getResources().newTheme();
            theme.applyStyle(r.info.getThemeResource(), true);
            if (theme.resolveAttribute(android.R.attr.windowAnimationStyle, out, true)) {
                TypedArray array = theme.obtainStyledAttributes(out.data, new int[] { android.R.attr.activityCloseEnterAnimation, android.R.attr.activityCloseExitAnimation });
                r.activity.overridePendingTransition(array.getResourceId(0, 0), array.getResourceId(1, 0));
                array.recycle();
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    return super.afterCall(who, method, args, result);
}
Also used : IBinder(android.os.IBinder) TypedArray(android.content.res.TypedArray) ActivityClientRecord(com.lody.virtual.client.ipc.ActivityClientRecord) Resources(android.content.res.Resources) TypedValue(android.util.TypedValue)

Aggregations

IBinder (android.os.IBinder)3 ActivityClientRecord (com.lody.virtual.client.ipc.ActivityClientRecord)3 ActivityInfo (android.content.pm.ActivityInfo)2 Resources (android.content.res.Resources)2 TypedArray (android.content.res.TypedArray)2 TypedValue (android.util.TypedValue)2 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 ChooserActivity (com.lody.virtual.client.stub.ChooserActivity)1