Skip to content

Commit

Permalink
[Refactor] Fix launching private activities in FM and Interceptor
Browse files Browse the repository at this point in the history
Signed-off-by: Muntashir Al-Islam <[email protected]>
  • Loading branch information
MuntashirAkon committed Jun 4, 2024
1 parent 3b007ce commit 65cc5cd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,22 @@ public static void startActivityViaAssist(@NonNull Context context, @NonNull Com
}

@SuppressWarnings("deprecation")
public static int startActivity(Intent intent, @UserIdInt int userHandle) throws RemoteException {
public static int startActivity(Intent intent, @UserIdInt int userHandle) throws SecurityException {
IActivityManager am = getActivityManager();
String callingPackage = SelfPermissions.getCallingPackage(Users.getSelfOrRemoteUid());
int result;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
result = am.startActivityAsUserWithFeature(null, callingPackage,
null, intent, intent.getType(), null, null,
0, 0, null, null, userHandle);
} else {
result = am.startActivityAsUser(null, callingPackage, intent, intent.getType(),
null, null, 0, 0, null,
null, userHandle);
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
return am.startActivityAsUserWithFeature(null, callingPackage,
null, intent, intent.getType(), null, null,
0, 0, null, null, userHandle);
} else {
return am.startActivityAsUser(null, callingPackage, intent, intent.getType(),
null, null, 0, 0, null,
null, userHandle);
}
} catch (RemoteException e) {
return ExUtils.rethrowFromSystemServer(e);
}
return result;
}

@SuppressWarnings("deprecation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.UserHandleHidden;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -70,7 +69,7 @@ protected void onAuthenticated(@Nullable Bundle savedInstanceState) {
} else {
try {
ActivityManagerCompat.startActivity(intent, userId);
} catch (RemoteException e) {
} catch (Throwable e) {
e.printStackTrace();
UIUtils.displayLongToast("Error: " + e.getMessage());
// Try assist instead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.UserHandleHidden;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -40,6 +41,7 @@
import java.util.Objects;

import io.github.muntashirakon.AppManager.R;
import io.github.muntashirakon.AppManager.compat.ActivityManagerCompat;
import io.github.muntashirakon.AppManager.fm.FmProvider;
import io.github.muntashirakon.AppManager.intercept.ActivityInterceptor;
import io.github.muntashirakon.AppManager.self.imagecache.ImageLoader;
Expand Down Expand Up @@ -238,8 +240,13 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
}
});
mViewModel.getIntentLiveData().observe(getViewLifecycleOwner(), intent -> {
startActivity(intent);
dismiss();
try {
// Resolved activities may contain non-exported activity
ActivityManagerCompat.startActivity(intent, UserHandleHidden.myUserId());
dismiss();
} catch (SecurityException e) {
UIUtils.displayLongToast("Failed: " + e.getMessage());
}
});
if (mCustomType == null) {
mViewModel.loadFileContentInfo(mPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -720,23 +720,23 @@ protected void onUpdateIntent(String modifiedContent) {
});
mClassNameView.addTextChangedListener(new IntentUpdateTextWatcher(mClassNameView) {
@Override
protected void onUpdateIntent(String modifiedContent) {
protected void onUpdateIntent(String modifiedComponent) {
if (mMutableIntent == null) return;
if (TextUtils.isEmpty(modifiedComponent)) {
mRequestedComponent = null;
mMutableIntent.setComponent(null);
return;
}
String packageName = mMutableIntent.getPackage();
if (packageName == null && !TextUtils.isEmpty(modifiedContent)) {
if (packageName == null) {
UIUtils.displayShortToast(R.string.set_package_name_first);
mAreTextWatchersActive = false;
mClassNameView.setText(null);
mAreTextWatchersActive = true;
return;
}
if (TextUtils.isEmpty(modifiedContent)) {
mRequestedComponent = null;
mMutableIntent.setComponent(null);
return;
}
mRequestedComponent = new ComponentName(packageName, (modifiedContent.startsWith(".") ?
packageName : "") + modifiedContent);
mRequestedComponent = new ComponentName(packageName, (modifiedComponent.startsWith(".") ?
packageName : "") + modifiedComponent);
mMutableIntent.setComponent(mRequestedComponent);
}
});
Expand Down Expand Up @@ -931,8 +931,13 @@ public void launchIntent(@NonNull Intent intent, boolean createChooser) {
// TODO: 4/2/22 Support sending activity result back to the original app
ActivityManagerCompat.startActivity(intent, mUserHandle);
} else {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mIntentLauncher.launch(intent);
try {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mIntentLauncher.launch(intent);
} catch (SecurityException e) {
// TODO: 4/6/24 Support sending activity result back to the original app
ActivityManagerCompat.startActivity(intent, mUserHandle);
}
}
}
} catch (Throwable th) {
Expand Down

0 comments on commit 65cc5cd

Please sign in to comment.