Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d750a7c6 authored by David Brazdil's avatar David Brazdil Committed by android-build-merger
Browse files

Merge "Show a warning toast/dialog when an app uses hidden APIs"

am: fbef950d

Change-Id: Icab7166bf83d2920c8d3f22774eafa4aea9fdaa4
parents 5ba62a21 fbef950d
Loading
Loading
Loading
Loading
+27 −2
Original line number Diff line number Diff line
@@ -128,6 +128,8 @@ import com.android.internal.app.WindowDecorActionBar;
import com.android.internal.policy.DecorView;
import com.android.internal.policy.PhoneWindow;

import dalvik.system.VMRuntime;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.lang.annotation.Retention;
@@ -7039,11 +7041,12 @@ public class Activity extends ContextThemeWrapper
        mFragments.dispatchStart();
        mFragments.reportLoaderStart();

        // This property is set for all builds except final release
        boolean isDlwarningEnabled = SystemProperties.getInt("ro.bionic.ld.warning", 0) == 1;
        boolean isAppDebuggable =
                (mApplication.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;

        // This property is set for all builds except final release
        boolean isDlwarningEnabled = SystemProperties.getInt("ro.bionic.ld.warning", 0) == 1;

        if (isAppDebuggable || isDlwarningEnabled) {
            String dlwarning = getDlWarning();
            if (dlwarning != null) {
@@ -7064,6 +7067,28 @@ public class Activity extends ContextThemeWrapper
            }
        }

        // We might disable this for final builds.
        boolean isApiWarningEnabled = true;

        if (isAppDebuggable || isApiWarningEnabled) {
            if (VMRuntime.getRuntime().hasUsedHiddenApi()) {
                String appName = getApplicationInfo().loadLabel(getPackageManager())
                        .toString();
                String warning = "Detected problems with API compatiblity\n"
                                 + "(please consult log for detail)";
                if (isAppDebuggable) {
                    new AlertDialog.Builder(this)
                        .setTitle(appName)
                        .setMessage(warning)
                        .setPositiveButton(android.R.string.ok, null)
                        .setCancelable(false)
                        .show();
                } else {
                    Toast.makeText(this, appName + "\n" + warning, Toast.LENGTH_LONG).show();
                }
            }
        }

        mActivityTransitionState.enterReady(this);
    }