Fix pmd errors and code style
This commit is contained in:
		
							parent
							
								
									d3a7107a0f
								
							
						
					
					
						commit
						f860257826
					
				@ -42,12 +42,12 @@ public class ApkSignatureVerifier {
 | 
			
		||||
 | 
			
		||||
    private static final String TAG = "ApkSignatureVerifier";
 | 
			
		||||
 | 
			
		||||
    private final Context mContext;
 | 
			
		||||
    private final PackageManager mPm;
 | 
			
		||||
    private final Context context;
 | 
			
		||||
    private final PackageManager pm;
 | 
			
		||||
 | 
			
		||||
    ApkSignatureVerifier(Context context) {
 | 
			
		||||
        mContext = context;
 | 
			
		||||
        mPm = context.getPackageManager();
 | 
			
		||||
        this.context = context;
 | 
			
		||||
        pm = context.getPackageManager();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean hasFDroidSignature(File apkFile) {
 | 
			
		||||
@ -66,7 +66,7 @@ public class ApkSignatureVerifier {
 | 
			
		||||
 | 
			
		||||
    private byte[] getApkSignature(File apkFile) {
 | 
			
		||||
        final String pkgPath = apkFile.getAbsolutePath();
 | 
			
		||||
        PackageInfo pkgInfo = mPm.getPackageArchiveInfo(pkgPath, PackageManager.GET_SIGNATURES);
 | 
			
		||||
        PackageInfo pkgInfo = pm.getPackageArchiveInfo(pkgPath, PackageManager.GET_SIGNATURES);
 | 
			
		||||
        return signatureToBytes(pkgInfo.signatures);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -74,7 +74,7 @@ public class ApkSignatureVerifier {
 | 
			
		||||
        try {
 | 
			
		||||
            // we do check the byte array of *all* signatures
 | 
			
		||||
            @SuppressLint("PackageManagerGetSignatures")
 | 
			
		||||
            PackageInfo pkgInfo = mPm.getPackageInfo(mContext.getPackageName(),
 | 
			
		||||
            PackageInfo pkgInfo = pm.getPackageInfo(context.getPackageName(),
 | 
			
		||||
                    PackageManager.GET_SIGNATURES);
 | 
			
		||||
            return signatureToBytes(pkgInfo.signatures);
 | 
			
		||||
        } catch (PackageManager.NameNotFoundException e) {
 | 
			
		||||
 | 
			
		||||
@ -45,7 +45,7 @@ public class DefaultInstaller extends Installer {
 | 
			
		||||
 | 
			
		||||
        Uri sanitizedUri;
 | 
			
		||||
        try {
 | 
			
		||||
            sanitizedUri = Installer.prepareApkFile(mContext, uri, packageName);
 | 
			
		||||
            sanitizedUri = Installer.prepareApkFile(context, uri, packageName);
 | 
			
		||||
        } catch (Installer.InstallFailedException e) {
 | 
			
		||||
            Log.e(TAG, "prepareApkFile failed", e);
 | 
			
		||||
            sendBroadcastInstall(uri, originatingUri, Installer.ACTION_INSTALL_INTERRUPTED,
 | 
			
		||||
@ -53,13 +53,13 @@ public class DefaultInstaller extends Installer {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Intent installIntent = new Intent(mContext, DefaultInstallerActivity.class);
 | 
			
		||||
        Intent installIntent = new Intent(context, DefaultInstallerActivity.class);
 | 
			
		||||
        installIntent.setAction(DefaultInstallerActivity.ACTION_INSTALL_PACKAGE);
 | 
			
		||||
        installIntent.putExtra(DefaultInstallerActivity.EXTRA_ORIGINATING_URI, originatingUri);
 | 
			
		||||
        installIntent.setData(sanitizedUri);
 | 
			
		||||
 | 
			
		||||
        PendingIntent installPendingIntent = PendingIntent.getActivity(
 | 
			
		||||
                mContext.getApplicationContext(),
 | 
			
		||||
                context.getApplicationContext(),
 | 
			
		||||
                uri.hashCode(),
 | 
			
		||||
                installIntent,
 | 
			
		||||
                PendingIntent.FLAG_UPDATE_CURRENT);
 | 
			
		||||
@ -72,12 +72,12 @@ public class DefaultInstaller extends Installer {
 | 
			
		||||
    protected void uninstallPackage(String packageName) {
 | 
			
		||||
        sendBroadcastUninstall(packageName, Installer.ACTION_UNINSTALL_STARTED);
 | 
			
		||||
 | 
			
		||||
        Intent uninstallIntent = new Intent(mContext, DefaultInstallerActivity.class);
 | 
			
		||||
        Intent uninstallIntent = new Intent(context, DefaultInstallerActivity.class);
 | 
			
		||||
        uninstallIntent.setAction(DefaultInstallerActivity.ACTION_UNINSTALL_PACKAGE);
 | 
			
		||||
        uninstallIntent.putExtra(
 | 
			
		||||
                DefaultInstallerActivity.EXTRA_UNINSTALL_PACKAGE_NAME, packageName);
 | 
			
		||||
        PendingIntent uninstallPendingIntent = PendingIntent.getActivity(
 | 
			
		||||
                mContext.getApplicationContext(),
 | 
			
		||||
                context.getApplicationContext(),
 | 
			
		||||
                packageName.hashCode(),
 | 
			
		||||
                uninstallIntent,
 | 
			
		||||
                PendingIntent.FLAG_UPDATE_CURRENT);
 | 
			
		||||
 | 
			
		||||
@ -31,7 +31,6 @@ import android.support.v4.app.FragmentActivity;
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
 | 
			
		||||
import org.fdroid.fdroid.R;
 | 
			
		||||
import org.fdroid.fdroid.Utils;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A transparent activity as a wrapper around AOSP's PackageInstaller Intents
 | 
			
		||||
@ -48,10 +47,10 @@ public class DefaultInstallerActivity extends FragmentActivity {
 | 
			
		||||
    private static final int REQUEST_CODE_INSTALL = 0;
 | 
			
		||||
    private static final int REQUEST_CODE_UNINSTALL = 1;
 | 
			
		||||
 | 
			
		||||
    private Uri mInstallOriginatingUri;
 | 
			
		||||
    private Uri mInstallUri;
 | 
			
		||||
    private Uri installOriginatingUri;
 | 
			
		||||
    private Uri installUri;
 | 
			
		||||
 | 
			
		||||
    private String mUninstallPackageName;
 | 
			
		||||
    private String uninstallPackageName;
 | 
			
		||||
 | 
			
		||||
    // for the broadcasts
 | 
			
		||||
    private DefaultInstaller installer;
 | 
			
		||||
@ -66,17 +65,17 @@ public class DefaultInstallerActivity extends FragmentActivity {
 | 
			
		||||
        String action = intent.getAction();
 | 
			
		||||
        switch (action) {
 | 
			
		||||
            case ACTION_INSTALL_PACKAGE: {
 | 
			
		||||
                mInstallUri = intent.getData();
 | 
			
		||||
                mInstallOriginatingUri = intent.getParcelableExtra(EXTRA_ORIGINATING_URI);
 | 
			
		||||
                installUri = intent.getData();
 | 
			
		||||
                installOriginatingUri = intent.getParcelableExtra(EXTRA_ORIGINATING_URI);
 | 
			
		||||
 | 
			
		||||
                installPackage(mInstallUri, mInstallOriginatingUri);
 | 
			
		||||
                installPackage(installUri, installOriginatingUri);
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            case ACTION_UNINSTALL_PACKAGE: {
 | 
			
		||||
                mUninstallPackageName = intent.getStringExtra(EXTRA_UNINSTALL_PACKAGE_NAME);
 | 
			
		||||
                uninstallPackageName = intent.getStringExtra(EXTRA_UNINSTALL_PACKAGE_NAME);
 | 
			
		||||
 | 
			
		||||
                uninstallPackage(mUninstallPackageName);
 | 
			
		||||
                uninstallPackage(uninstallPackageName);
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
            default: {
 | 
			
		||||
@ -87,8 +86,6 @@ public class DefaultInstallerActivity extends FragmentActivity {
 | 
			
		||||
 | 
			
		||||
    @SuppressLint("InlinedApi")
 | 
			
		||||
    private void installPackage(Uri uri, Uri originatingUri) {
 | 
			
		||||
        Utils.debugLog(TAG, "Installing from " + uri);
 | 
			
		||||
 | 
			
		||||
        if (uri == null) {
 | 
			
		||||
            throw new RuntimeException("Set the data uri to point to an apk location!");
 | 
			
		||||
        }
 | 
			
		||||
@ -135,13 +132,11 @@ public class DefaultInstallerActivity extends FragmentActivity {
 | 
			
		||||
                    "This Android rom does not support ACTION_INSTALL_PACKAGE!");
 | 
			
		||||
            finish();
 | 
			
		||||
        }
 | 
			
		||||
        installer.sendBroadcastInstall(mInstallUri, mInstallOriginatingUri,
 | 
			
		||||
        installer.sendBroadcastInstall(installUri, installOriginatingUri,
 | 
			
		||||
                Installer.ACTION_INSTALL_STARTED);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected void uninstallPackage(String packageName) {
 | 
			
		||||
        Intent intent = new Intent();
 | 
			
		||||
 | 
			
		||||
        // check that the package is installed
 | 
			
		||||
        try {
 | 
			
		||||
            getPackageManager().getPackageInfo(packageName, 0);
 | 
			
		||||
@ -154,6 +149,7 @@ public class DefaultInstallerActivity extends FragmentActivity {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Uri uri = Uri.fromParts("package", packageName, null);
 | 
			
		||||
        Intent intent = new Intent();
 | 
			
		||||
        intent.setData(uri);
 | 
			
		||||
 | 
			
		||||
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
 | 
			
		||||
@ -183,33 +179,33 @@ public class DefaultInstallerActivity extends FragmentActivity {
 | 
			
		||||
                 * never executed on Androids < 4.0
 | 
			
		||||
                 */
 | 
			
		||||
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
 | 
			
		||||
                    installer.sendBroadcastInstall(mInstallUri, mInstallOriginatingUri,
 | 
			
		||||
                    installer.sendBroadcastInstall(installUri, installOriginatingUri,
 | 
			
		||||
                            Installer.ACTION_INSTALL_COMPLETE);
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // Fallback on N for https://gitlab.com/fdroid/fdroidclient/issues/631
 | 
			
		||||
                if ("N".equals(Build.VERSION.CODENAME)) {
 | 
			
		||||
                    installer.sendBroadcastInstall(mInstallUri, mInstallOriginatingUri,
 | 
			
		||||
                    installer.sendBroadcastInstall(installUri, installOriginatingUri,
 | 
			
		||||
                            Installer.ACTION_INSTALL_COMPLETE);
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                switch (resultCode) {
 | 
			
		||||
                    case Activity.RESULT_OK: {
 | 
			
		||||
                        installer.sendBroadcastInstall(mInstallUri, mInstallOriginatingUri,
 | 
			
		||||
                        installer.sendBroadcastInstall(installUri, installOriginatingUri,
 | 
			
		||||
                                Installer.ACTION_INSTALL_COMPLETE);
 | 
			
		||||
                        break;
 | 
			
		||||
                    }
 | 
			
		||||
                    case Activity.RESULT_CANCELED: {
 | 
			
		||||
                        installer.sendBroadcastInstall(mInstallUri, mInstallOriginatingUri,
 | 
			
		||||
                        installer.sendBroadcastInstall(installUri, installOriginatingUri,
 | 
			
		||||
                                Installer.ACTION_INSTALL_INTERRUPTED);
 | 
			
		||||
                        break;
 | 
			
		||||
                    }
 | 
			
		||||
                    default:
 | 
			
		||||
                    case Activity.RESULT_FIRST_USER: {
 | 
			
		||||
                    case Activity.RESULT_FIRST_USER:
 | 
			
		||||
                    default: {
 | 
			
		||||
                        // AOSP returns Activity.RESULT_FIRST_USER on error
 | 
			
		||||
                        installer.sendBroadcastInstall(mInstallUri, mInstallOriginatingUri,
 | 
			
		||||
                        installer.sendBroadcastInstall(installUri, installOriginatingUri,
 | 
			
		||||
                                Installer.ACTION_INSTALL_INTERRUPTED,
 | 
			
		||||
                                getString(R.string.install_error_unknown));
 | 
			
		||||
                        break;
 | 
			
		||||
@ -221,26 +217,26 @@ public class DefaultInstallerActivity extends FragmentActivity {
 | 
			
		||||
            case REQUEST_CODE_UNINSTALL: {
 | 
			
		||||
                // resultCode is always 0 on Android < 4.0.
 | 
			
		||||
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
 | 
			
		||||
                    installer.sendBroadcastUninstall(mUninstallPackageName,
 | 
			
		||||
                    installer.sendBroadcastUninstall(uninstallPackageName,
 | 
			
		||||
                            Installer.ACTION_UNINSTALL_COMPLETE);
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                switch (resultCode) {
 | 
			
		||||
                    case Activity.RESULT_OK: {
 | 
			
		||||
                        installer.sendBroadcastUninstall(mUninstallPackageName,
 | 
			
		||||
                        installer.sendBroadcastUninstall(uninstallPackageName,
 | 
			
		||||
                                Installer.ACTION_UNINSTALL_COMPLETE);
 | 
			
		||||
                        break;
 | 
			
		||||
                    }
 | 
			
		||||
                    case Activity.RESULT_CANCELED: {
 | 
			
		||||
                        installer.sendBroadcastUninstall(mUninstallPackageName,
 | 
			
		||||
                        installer.sendBroadcastUninstall(uninstallPackageName,
 | 
			
		||||
                                Installer.ACTION_UNINSTALL_INTERRUPTED);
 | 
			
		||||
                        break;
 | 
			
		||||
                    }
 | 
			
		||||
                    default:
 | 
			
		||||
                    case Activity.RESULT_FIRST_USER: {
 | 
			
		||||
                    case Activity.RESULT_FIRST_USER:
 | 
			
		||||
                    default: {
 | 
			
		||||
                        // AOSP UninstallAppProgress returns RESULT_FIRST_USER on error
 | 
			
		||||
                        installer.sendBroadcastUninstall(mUninstallPackageName,
 | 
			
		||||
                        installer.sendBroadcastUninstall(uninstallPackageName,
 | 
			
		||||
                                Installer.ACTION_UNINSTALL_INTERRUPTED,
 | 
			
		||||
                                getString(R.string.uninstall_error_unknown));
 | 
			
		||||
                        break;
 | 
			
		||||
 | 
			
		||||
@ -45,7 +45,7 @@ public class ExtensionInstaller extends Installer {
 | 
			
		||||
    protected void installPackage(Uri uri, Uri originatingUri, String packageName) {
 | 
			
		||||
        Uri sanitizedUri;
 | 
			
		||||
        try {
 | 
			
		||||
            sanitizedUri = Installer.prepareApkFile(mContext, uri, packageName);
 | 
			
		||||
            sanitizedUri = Installer.prepareApkFile(context, uri, packageName);
 | 
			
		||||
        } catch (InstallFailedException e) {
 | 
			
		||||
            Log.e(TAG, "prepareApkFile failed", e);
 | 
			
		||||
            sendBroadcastInstall(uri, originatingUri, Installer.ACTION_INSTALL_INTERRUPTED,
 | 
			
		||||
@ -55,17 +55,17 @@ public class ExtensionInstaller extends Installer {
 | 
			
		||||
 | 
			
		||||
        // extension must be signed with the same public key as main F-Droid
 | 
			
		||||
        // NOTE: Disabled for debug builds to be able to use official extension from repo
 | 
			
		||||
        ApkSignatureVerifier signatureVerifier = new ApkSignatureVerifier(mContext);
 | 
			
		||||
        ApkSignatureVerifier signatureVerifier = new ApkSignatureVerifier(context);
 | 
			
		||||
        if (!BuildConfig.DEBUG && !signatureVerifier.hasFDroidSignature(new File(sanitizedUri.getPath()))) {
 | 
			
		||||
            sendBroadcastInstall(uri, originatingUri, Installer.ACTION_INSTALL_INTERRUPTED,
 | 
			
		||||
                    "APK signature of extension not correct!");
 | 
			
		||||
        }
 | 
			
		||||
        Intent installIntent = new Intent(mContext, InstallExtensionDialogActivity.class);
 | 
			
		||||
        Intent installIntent = new Intent(context, InstallExtensionDialogActivity.class);
 | 
			
		||||
        installIntent.setAction(InstallExtensionDialogActivity.ACTION_INSTALL);
 | 
			
		||||
        installIntent.setData(sanitizedUri);
 | 
			
		||||
 | 
			
		||||
        PendingIntent installPendingIntent = PendingIntent.getActivity(
 | 
			
		||||
                mContext.getApplicationContext(),
 | 
			
		||||
                context.getApplicationContext(),
 | 
			
		||||
                uri.hashCode(),
 | 
			
		||||
                installIntent,
 | 
			
		||||
                PendingIntent.FLAG_UPDATE_CURRENT);
 | 
			
		||||
@ -81,11 +81,11 @@ public class ExtensionInstaller extends Installer {
 | 
			
		||||
    protected void uninstallPackage(String packageName) {
 | 
			
		||||
        sendBroadcastUninstall(packageName, Installer.ACTION_UNINSTALL_STARTED);
 | 
			
		||||
 | 
			
		||||
        Intent uninstallIntent = new Intent(mContext, InstallExtensionDialogActivity.class);
 | 
			
		||||
        Intent uninstallIntent = new Intent(context, InstallExtensionDialogActivity.class);
 | 
			
		||||
        uninstallIntent.setAction(InstallExtensionDialogActivity.ACTION_UNINSTALL);
 | 
			
		||||
 | 
			
		||||
        PendingIntent uninstallPendingIntent = PendingIntent.getActivity(
 | 
			
		||||
                mContext.getApplicationContext(),
 | 
			
		||||
                context.getApplicationContext(),
 | 
			
		||||
                packageName.hashCode(),
 | 
			
		||||
                uninstallIntent,
 | 
			
		||||
                PendingIntent.FLAG_UPDATE_CURRENT);
 | 
			
		||||
 | 
			
		||||
@ -340,8 +340,7 @@ public class InstallManagerService extends Service {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private String getAppName(Apk apk) {
 | 
			
		||||
        App app = ACTIVE_APPS.get(apk.packageName);
 | 
			
		||||
        return app.name;
 | 
			
		||||
        return ACTIVE_APPS.get(apk.packageName).name;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
@ -46,9 +46,9 @@ import java.security.NoSuchAlgorithmException;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
public abstract class Installer {
 | 
			
		||||
    final Context mContext;
 | 
			
		||||
    final PackageManager mPm;
 | 
			
		||||
    private LocalBroadcastManager localBroadcastManager;
 | 
			
		||||
    final Context context;
 | 
			
		||||
    final PackageManager pm;
 | 
			
		||||
    final LocalBroadcastManager localBroadcastManager;
 | 
			
		||||
 | 
			
		||||
    public static final String ACTION_INSTALL_STARTED = "org.fdroid.fdroid.installer.Installer.action.INSTALL_STARTED";
 | 
			
		||||
    public static final String ACTION_INSTALL_COMPLETE = "org.fdroid.fdroid.installer.Installer.action.INSTALL_COMPLETE";
 | 
			
		||||
@ -83,8 +83,8 @@ public abstract class Installer {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Installer(Context context) {
 | 
			
		||||
        this.mContext = context;
 | 
			
		||||
        this.mPm = context.getPackageManager();
 | 
			
		||||
        this.context = context;
 | 
			
		||||
        this.pm = context.getPackageManager();
 | 
			
		||||
        localBroadcastManager = LocalBroadcastManager.getInstance(context);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -163,7 +163,7 @@ public abstract class Installer {
 | 
			
		||||
        int count = newPermissionCount(apk);
 | 
			
		||||
        if (count > 0) {
 | 
			
		||||
            Uri uri = ApkProvider.getContentUri(apk);
 | 
			
		||||
            Intent intent = new Intent(mContext, InstallConfirmActivity.class);
 | 
			
		||||
            Intent intent = new Intent(context, InstallConfirmActivity.class);
 | 
			
		||||
            intent.setData(uri);
 | 
			
		||||
 | 
			
		||||
            return intent;
 | 
			
		||||
@ -181,12 +181,12 @@ public abstract class Installer {
 | 
			
		||||
        //    return 0;
 | 
			
		||||
        //}
 | 
			
		||||
 | 
			
		||||
        AppDiff appDiff = new AppDiff(mContext.getPackageManager(), apk);
 | 
			
		||||
        AppDiff appDiff = new AppDiff(context.getPackageManager(), apk);
 | 
			
		||||
        if (appDiff.mPkgInfo == null) {
 | 
			
		||||
            // could not get diff because we couldn't parse the package
 | 
			
		||||
            throw new RuntimeException("cannot parse!");
 | 
			
		||||
        }
 | 
			
		||||
        AppSecurityPermissions perms = new AppSecurityPermissions(mContext, appDiff.mPkgInfo);
 | 
			
		||||
        AppSecurityPermissions perms = new AppSecurityPermissions(context, appDiff.mPkgInfo);
 | 
			
		||||
        if (appDiff.mInstalledAppInfo != null) {
 | 
			
		||||
            // update to an existing app
 | 
			
		||||
            return perms.getPermissionCount(AppSecurityPermissions.WHICH_NEW);
 | 
			
		||||
@ -200,7 +200,7 @@ public abstract class Installer {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Intent intent = new Intent(mContext, UninstallDialogActivity.class);
 | 
			
		||||
        Intent intent = new Intent(context, UninstallDialogActivity.class);
 | 
			
		||||
        intent.putExtra(Installer.EXTRA_PACKAGE_NAME, packageName);
 | 
			
		||||
 | 
			
		||||
        return intent;
 | 
			
		||||
 | 
			
		||||
@ -28,7 +28,6 @@ import android.os.IBinder;
 | 
			
		||||
import android.os.Looper;
 | 
			
		||||
import android.os.Message;
 | 
			
		||||
import android.os.Process;
 | 
			
		||||
import android.support.v4.content.LocalBroadcastManager;
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
 | 
			
		||||
import org.fdroid.fdroid.Utils;
 | 
			
		||||
@ -44,8 +43,6 @@ public class InstallerService extends Service {
 | 
			
		||||
 | 
			
		||||
    private volatile Looper serviceLooper;
 | 
			
		||||
    private static volatile ServiceHandler serviceHandler;
 | 
			
		||||
    private LocalBroadcastManager localBroadcastManager;
 | 
			
		||||
    private Installer installer;
 | 
			
		||||
 | 
			
		||||
    private final class ServiceHandler extends Handler {
 | 
			
		||||
        ServiceHandler(Looper looper) {
 | 
			
		||||
@ -70,7 +67,6 @@ public class InstallerService extends Service {
 | 
			
		||||
 | 
			
		||||
        serviceLooper = thread.getLooper();
 | 
			
		||||
        serviceHandler = new ServiceHandler(serviceLooper);
 | 
			
		||||
        localBroadcastManager = LocalBroadcastManager.getInstance(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@ -118,7 +114,7 @@ public class InstallerService extends Service {
 | 
			
		||||
 | 
			
		||||
    protected void handleIntent(Intent intent) {
 | 
			
		||||
        String packageName = intent.getStringExtra(Installer.EXTRA_PACKAGE_NAME);
 | 
			
		||||
        installer = InstallerFactory.create(this, packageName);
 | 
			
		||||
        Installer installer = InstallerFactory.create(this, packageName);
 | 
			
		||||
 | 
			
		||||
        switch (intent.getAction()) {
 | 
			
		||||
            case ACTION_INSTALL: {
 | 
			
		||||
 | 
			
		||||
@ -326,7 +326,7 @@ public class PrivilegedInstaller extends Installer {
 | 
			
		||||
 | 
			
		||||
        final Uri sanitizedUri;
 | 
			
		||||
        try {
 | 
			
		||||
            sanitizedUri = Installer.prepareApkFile(mContext, uri, packageName);
 | 
			
		||||
            sanitizedUri = Installer.prepareApkFile(context, uri, packageName);
 | 
			
		||||
        } catch (Installer.InstallFailedException e) {
 | 
			
		||||
            Log.e(TAG, "prepareApkFile failed", e);
 | 
			
		||||
            sendBroadcastInstall(uri, originatingUri, Installer.ACTION_INSTALL_INTERRUPTED,
 | 
			
		||||
@ -367,7 +367,7 @@ public class PrivilegedInstaller extends Installer {
 | 
			
		||||
 | 
			
		||||
        Intent serviceIntent = new Intent(PRIVILEGED_EXTENSION_SERVICE_INTENT);
 | 
			
		||||
        serviceIntent.setPackage(PRIVILEGED_EXTENSION_PACKAGE_NAME);
 | 
			
		||||
        mContext.getApplicationContext().bindService(serviceIntent, mServiceConnection,
 | 
			
		||||
        context.getApplicationContext().bindService(serviceIntent, mServiceConnection,
 | 
			
		||||
                Context.BIND_AUTO_CREATE);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -378,7 +378,7 @@ public class PrivilegedInstaller extends Installer {
 | 
			
		||||
        ApplicationInfo appInfo;
 | 
			
		||||
        try {
 | 
			
		||||
            //noinspection WrongConstant (lint is actually wrong here!)
 | 
			
		||||
            appInfo = mPm.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
 | 
			
		||||
            appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
 | 
			
		||||
        } catch (PackageManager.NameNotFoundException e) {
 | 
			
		||||
            Log.w(TAG, "Failed to get ApplicationInfo for uninstalling");
 | 
			
		||||
            return;
 | 
			
		||||
@ -402,9 +402,9 @@ public class PrivilegedInstaller extends Installer {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // TODO: move this to methods in activity/ Installer with activity context!
 | 
			
		||||
        final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
 | 
			
		||||
        builder.setTitle(appInfo.loadLabel(mPm));
 | 
			
		||||
        builder.setIcon(appInfo.loadIcon(mPm));
 | 
			
		||||
        final AlertDialog.Builder builder = new AlertDialog.Builder(context);
 | 
			
		||||
        builder.setTitle(appInfo.loadLabel(pm));
 | 
			
		||||
        builder.setIcon(appInfo.loadIcon(pm));
 | 
			
		||||
        builder.setPositiveButton(android.R.string.ok,
 | 
			
		||||
                new DialogInterface.OnClickListener() {
 | 
			
		||||
                    @Override
 | 
			
		||||
@ -463,7 +463,7 @@ public class PrivilegedInstaller extends Installer {
 | 
			
		||||
 | 
			
		||||
        Intent serviceIntent = new Intent(PRIVILEGED_EXTENSION_SERVICE_INTENT);
 | 
			
		||||
        serviceIntent.setPackage(PRIVILEGED_EXTENSION_PACKAGE_NAME);
 | 
			
		||||
        mContext.getApplicationContext().bindService(serviceIntent, mServiceConnection,
 | 
			
		||||
        context.getApplicationContext().bindService(serviceIntent, mServiceConnection,
 | 
			
		||||
                Context.BIND_AUTO_CREATE);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -60,7 +60,7 @@ public class InstallExtensionDialogActivity extends FragmentActivity {
 | 
			
		||||
    public static final String ACTION_POST_INSTALL = "post_install";
 | 
			
		||||
    public static final String ACTION_FIRST_TIME = "first_time";
 | 
			
		||||
 | 
			
		||||
    private String apkFile;
 | 
			
		||||
    private String apkPath;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void onCreate(Bundle savedInstanceState) {
 | 
			
		||||
@ -74,7 +74,8 @@ public class InstallExtensionDialogActivity extends FragmentActivity {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        apkFile = (new File(getIntent().getData().getPath())).getAbsolutePath();
 | 
			
		||||
        File apkFile = new File(getIntent().getData().getPath());
 | 
			
		||||
        apkPath = apkFile.getAbsolutePath();
 | 
			
		||||
 | 
			
		||||
        switch (getIntent().getAction()) {
 | 
			
		||||
            case ACTION_UNINSTALL:
 | 
			
		||||
@ -335,7 +336,7 @@ public class InstallExtensionDialogActivity extends FragmentActivity {
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        protected Void doInBackground(Void... voids) {
 | 
			
		||||
            InstallExtension.create(getApplicationContext()).runInstall(apkFile);
 | 
			
		||||
            InstallExtension.create(getApplicationContext()).runInstall(apkPath);
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
@ -23,7 +23,6 @@ import android.content.DialogInterface;
 | 
			
		||||
import android.content.DialogInterface.OnCancelListener;
 | 
			
		||||
import android.content.Intent;
 | 
			
		||||
import android.content.pm.ApplicationInfo;
 | 
			
		||||
import android.content.pm.PackageManager;
 | 
			
		||||
import android.graphics.Bitmap;
 | 
			
		||||
import android.net.Uri;
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
@ -60,17 +59,15 @@ public class InstallConfirmActivity extends FragmentActivity implements OnCancel
 | 
			
		||||
 | 
			
		||||
    private Intent intent;
 | 
			
		||||
 | 
			
		||||
    private PackageManager mPm;
 | 
			
		||||
 | 
			
		||||
    private AppDiff mAppDiff;
 | 
			
		||||
    private AppDiff appDiff;
 | 
			
		||||
 | 
			
		||||
    // View for install progress
 | 
			
		||||
    private View mInstallConfirm;
 | 
			
		||||
    private View installConfirm;
 | 
			
		||||
    // Buttons to indicate user acceptance
 | 
			
		||||
    private Button mOk;
 | 
			
		||||
    private Button mCancel;
 | 
			
		||||
    private CaffeinatedScrollView mScrollView;
 | 
			
		||||
    private boolean mOkCanInstall;
 | 
			
		||||
    private Button okButton;
 | 
			
		||||
    private Button cancelButton;
 | 
			
		||||
    private CaffeinatedScrollView scrollView;
 | 
			
		||||
    private boolean okCanInstall;
 | 
			
		||||
 | 
			
		||||
    private static final String TAB_ID_ALL = "all";
 | 
			
		||||
    private static final String TAB_ID_NEW = "new";
 | 
			
		||||
@ -106,27 +103,27 @@ public class InstallConfirmActivity extends FragmentActivity implements OnCancel
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        boolean permVisible = false;
 | 
			
		||||
        mScrollView = null;
 | 
			
		||||
        mOkCanInstall = false;
 | 
			
		||||
        scrollView = null;
 | 
			
		||||
        okCanInstall = false;
 | 
			
		||||
        int msg = 0;
 | 
			
		||||
        AppSecurityPermissions perms = new AppSecurityPermissions(this, mAppDiff.mPkgInfo);
 | 
			
		||||
        if (mAppDiff.mInstalledAppInfo != null) {
 | 
			
		||||
            msg = (mAppDiff.mInstalledAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0
 | 
			
		||||
        AppSecurityPermissions perms = new AppSecurityPermissions(this, appDiff.mPkgInfo);
 | 
			
		||||
        if (appDiff.mInstalledAppInfo != null) {
 | 
			
		||||
            msg = (appDiff.mInstalledAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0
 | 
			
		||||
                    ? R.string.install_confirm_update_system
 | 
			
		||||
                    : R.string.install_confirm_update;
 | 
			
		||||
            mScrollView = new CaffeinatedScrollView(this);
 | 
			
		||||
            mScrollView.setFillViewport(true);
 | 
			
		||||
            scrollView = new CaffeinatedScrollView(this);
 | 
			
		||||
            scrollView.setFillViewport(true);
 | 
			
		||||
            final boolean newPermissionsFound =
 | 
			
		||||
                    perms.getPermissionCount(AppSecurityPermissions.WHICH_NEW) > 0;
 | 
			
		||||
            if (newPermissionsFound) {
 | 
			
		||||
                permVisible = true;
 | 
			
		||||
                mScrollView.addView(perms.getPermissionsView(
 | 
			
		||||
                scrollView.addView(perms.getPermissionsView(
 | 
			
		||||
                        AppSecurityPermissions.WHICH_NEW));
 | 
			
		||||
            } else {
 | 
			
		||||
                throw new RuntimeException("This should not happen. No new permissions were found but InstallConfirmActivity has been started!");
 | 
			
		||||
            }
 | 
			
		||||
            adapter.addTab(tabHost.newTabSpec(TAB_ID_NEW).setIndicator(
 | 
			
		||||
                    getText(R.string.newPerms)), mScrollView);
 | 
			
		||||
                    getText(R.string.newPerms)), scrollView);
 | 
			
		||||
        } else {
 | 
			
		||||
            findViewById(R.id.tabscontainer).setVisibility(View.GONE);
 | 
			
		||||
            findViewById(R.id.divider).setVisibility(View.VISIBLE);
 | 
			
		||||
@ -137,8 +134,8 @@ public class InstallConfirmActivity extends FragmentActivity implements OnCancel
 | 
			
		||||
            LayoutInflater inflater = (LayoutInflater) getSystemService(
 | 
			
		||||
                    Context.LAYOUT_INFLATER_SERVICE);
 | 
			
		||||
            View root = inflater.inflate(R.layout.permissions_list, null);
 | 
			
		||||
            if (mScrollView == null) {
 | 
			
		||||
                mScrollView = (CaffeinatedScrollView) root.findViewById(R.id.scrollview);
 | 
			
		||||
            if (scrollView == null) {
 | 
			
		||||
                scrollView = (CaffeinatedScrollView) root.findViewById(R.id.scrollview);
 | 
			
		||||
            }
 | 
			
		||||
            final ViewGroup permList = (ViewGroup) root.findViewById(R.id.permission_list);
 | 
			
		||||
            permList.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_ALL));
 | 
			
		||||
@ -147,10 +144,10 @@ public class InstallConfirmActivity extends FragmentActivity implements OnCancel
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!permVisible) {
 | 
			
		||||
            if (mAppDiff.mInstalledAppInfo != null) {
 | 
			
		||||
            if (appDiff.mInstalledAppInfo != null) {
 | 
			
		||||
                // This is an update to an application, but there are no
 | 
			
		||||
                // permissions at all.
 | 
			
		||||
                msg = (mAppDiff.mInstalledAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0
 | 
			
		||||
                msg = (appDiff.mInstalledAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0
 | 
			
		||||
                        ? R.string.install_confirm_update_system_no_perms
 | 
			
		||||
                        : R.string.install_confirm_update_no_perms;
 | 
			
		||||
            } else {
 | 
			
		||||
@ -160,27 +157,27 @@ public class InstallConfirmActivity extends FragmentActivity implements OnCancel
 | 
			
		||||
            tabHost.setVisibility(View.GONE);
 | 
			
		||||
            findViewById(R.id.filler).setVisibility(View.VISIBLE);
 | 
			
		||||
            findViewById(R.id.divider).setVisibility(View.GONE);
 | 
			
		||||
            mScrollView = null;
 | 
			
		||||
            scrollView = null;
 | 
			
		||||
        }
 | 
			
		||||
        if (msg != 0) {
 | 
			
		||||
            ((TextView) findViewById(R.id.install_confirm)).setText(msg);
 | 
			
		||||
        }
 | 
			
		||||
        mInstallConfirm.setVisibility(View.VISIBLE);
 | 
			
		||||
        mOk = (Button) findViewById(R.id.ok_button);
 | 
			
		||||
        mCancel = (Button) findViewById(R.id.cancel_button);
 | 
			
		||||
        mOk.setOnClickListener(this);
 | 
			
		||||
        mCancel.setOnClickListener(this);
 | 
			
		||||
        if (mScrollView == null) {
 | 
			
		||||
        installConfirm.setVisibility(View.VISIBLE);
 | 
			
		||||
        okButton = (Button) findViewById(R.id.ok_button);
 | 
			
		||||
        cancelButton = (Button) findViewById(R.id.cancel_button);
 | 
			
		||||
        okButton.setOnClickListener(this);
 | 
			
		||||
        cancelButton.setOnClickListener(this);
 | 
			
		||||
        if (scrollView == null) {
 | 
			
		||||
            // There is nothing to scroll view, so the ok button is immediately
 | 
			
		||||
            // set to install.
 | 
			
		||||
            mOk.setText(R.string.menu_install);
 | 
			
		||||
            mOkCanInstall = true;
 | 
			
		||||
            okButton.setText(R.string.menu_install);
 | 
			
		||||
            okCanInstall = true;
 | 
			
		||||
        } else {
 | 
			
		||||
            mScrollView.setFullScrollAction(new Runnable() {
 | 
			
		||||
            scrollView.setFullScrollAction(new Runnable() {
 | 
			
		||||
                @Override
 | 
			
		||||
                public void run() {
 | 
			
		||||
                    mOk.setText(R.string.menu_install);
 | 
			
		||||
                    mOkCanInstall = true;
 | 
			
		||||
                    okButton.setText(R.string.menu_install);
 | 
			
		||||
                    okCanInstall = true;
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
@ -192,15 +189,13 @@ public class InstallConfirmActivity extends FragmentActivity implements OnCancel
 | 
			
		||||
 | 
			
		||||
        ((FDroidApp) getApplication()).applyDialogTheme(this);
 | 
			
		||||
 | 
			
		||||
        mPm = getPackageManager();
 | 
			
		||||
 | 
			
		||||
        intent = getIntent();
 | 
			
		||||
        Uri uri = intent.getData();
 | 
			
		||||
        Apk apk = ApkProvider.Helper.find(this, uri, ApkProvider.DataColumns.ALL);
 | 
			
		||||
        mApp = AppProvider.Helper.findByPackageName(getContentResolver(), apk.packageName);
 | 
			
		||||
 | 
			
		||||
        mAppDiff = new AppDiff(mPm, apk);
 | 
			
		||||
        if (mAppDiff.mPkgInfo == null) {
 | 
			
		||||
        appDiff = new AppDiff(getPackageManager(), apk);
 | 
			
		||||
        if (appDiff.mPkgInfo == null) {
 | 
			
		||||
            setResult(RESULT_CANNOT_PARSE, intent);
 | 
			
		||||
            finish();
 | 
			
		||||
        }
 | 
			
		||||
@ -212,8 +207,8 @@ public class InstallConfirmActivity extends FragmentActivity implements OnCancel
 | 
			
		||||
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
 | 
			
		||||
                ViewGroup.LayoutParams.WRAP_CONTENT);
 | 
			
		||||
 | 
			
		||||
        mInstallConfirm = findViewById(R.id.install_confirm_panel);
 | 
			
		||||
        mInstallConfirm.setVisibility(View.INVISIBLE);
 | 
			
		||||
        installConfirm = findViewById(R.id.install_confirm_panel);
 | 
			
		||||
        installConfirm.setVisibility(View.INVISIBLE);
 | 
			
		||||
 | 
			
		||||
        startInstallConfirm();
 | 
			
		||||
    }
 | 
			
		||||
@ -224,14 +219,14 @@ public class InstallConfirmActivity extends FragmentActivity implements OnCancel
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void onClick(View v) {
 | 
			
		||||
        if (v == mOk) {
 | 
			
		||||
            if (mOkCanInstall || mScrollView == null) {
 | 
			
		||||
        if (v == okButton) {
 | 
			
		||||
            if (okCanInstall || scrollView == null) {
 | 
			
		||||
                setResult(RESULT_OK, intent);
 | 
			
		||||
                finish();
 | 
			
		||||
            } else {
 | 
			
		||||
                mScrollView.pageScroll(View.FOCUS_DOWN);
 | 
			
		||||
                scrollView.pageScroll(View.FOCUS_DOWN);
 | 
			
		||||
            }
 | 
			
		||||
        } else if (v == mCancel) {
 | 
			
		||||
        } else if (v == cancelButton) {
 | 
			
		||||
            setResult(RESULT_CANCELED, intent);
 | 
			
		||||
            finish();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -38,7 +38,6 @@ import org.fdroid.fdroid.NfcHelper;
 | 
			
		||||
import org.fdroid.fdroid.Preferences;
 | 
			
		||||
import org.fdroid.fdroid.R;
 | 
			
		||||
import org.fdroid.fdroid.Utils;
 | 
			
		||||
import org.fdroid.fdroid.compat.PackageManagerCompat;
 | 
			
		||||
import org.fdroid.fdroid.data.Apk;
 | 
			
		||||
import org.fdroid.fdroid.data.ApkProvider;
 | 
			
		||||
import org.fdroid.fdroid.data.App;
 | 
			
		||||
@ -122,7 +121,6 @@ public class SwapWorkflowActivity extends AppCompatActivity {
 | 
			
		||||
    private PrepareSwapRepo updateSwappableAppsTask;
 | 
			
		||||
    private NewRepoConfig confirmSwapConfig;
 | 
			
		||||
    private LocalBroadcastManager localBroadcastManager;
 | 
			
		||||
    private BroadcastReceiver downloadCompleteReceiver;
 | 
			
		||||
 | 
			
		||||
    @NonNull
 | 
			
		||||
    private final ServiceConnection serviceConnection = new ServiceConnection() {
 | 
			
		||||
@ -776,7 +774,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
 | 
			
		||||
    public void install(@NonNull final App app) {
 | 
			
		||||
        final Apk apk = ApkProvider.Helper.find(this, app.packageName, app.suggestedVersionCode);
 | 
			
		||||
        String urlString = apk.getUrl();
 | 
			
		||||
        downloadCompleteReceiver = new BroadcastReceiver() {
 | 
			
		||||
        BroadcastReceiver downloadCompleteReceiver = new BroadcastReceiver() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onReceive(Context context, Intent intent) {
 | 
			
		||||
                String path = intent.getStringExtra(Downloader.EXTRA_DOWNLOAD_PATH);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user