Search in sources :

Example 16 with AndroidRuntimeException

use of android.util.AndroidRuntimeException in project XobotOS by xamarin.

the class MessageQueue method enqueueMessage.

final boolean enqueueMessage(Message msg, long when) {
    if (msg.isInUse()) {
        throw new AndroidRuntimeException(msg + " This message is already in use.");
    }
    if (msg.target == null && !mQuitAllowed) {
        throw new RuntimeException("Main thread not allowed to quit");
    }
    final boolean needWake;
    synchronized (this) {
        if (mQuiting) {
            RuntimeException e = new RuntimeException(msg.target + " sending message to a Handler on a dead thread");
            Log.w("MessageQueue", e.getMessage(), e);
            return false;
        } else if (msg.target == null) {
            mQuiting = true;
        }
        msg.when = when;
        //Log.d("MessageQueue", "Enqueing: " + msg);
        Message p = mMessages;
        if (p == null || when == 0 || when < p.when) {
            msg.next = p;
            mMessages = msg;
            // new head, might need to wake up
            needWake = mBlocked;
        } else {
            Message prev = null;
            while (p != null && p.when <= when) {
                prev = p;
                p = p.next;
            }
            msg.next = prev.next;
            prev.next = msg;
            // still waiting on head, no need to wake up
            needWake = false;
        }
    }
    if (needWake) {
        nativeWake(mPtr);
    }
    return true;
}
Also used : AndroidRuntimeException(android.util.AndroidRuntimeException) AndroidRuntimeException(android.util.AndroidRuntimeException)

Example 17 with AndroidRuntimeException

use of android.util.AndroidRuntimeException in project android_frameworks_base by DirtyUnicorns.

the class AudioService method killBackgroundUserProcessesWithRecordAudioPermission.

// end class AudioServiceUserRestrictionsListener
private void killBackgroundUserProcessesWithRecordAudioPermission(UserInfo oldUser) {
    PackageManager pm = mContext.getPackageManager();
    // Find the home activity of the user. It should not be killed to avoid expensive restart,
    // when the user switches back. For managed profiles, we should kill all recording apps
    ComponentName homeActivityName = null;
    if (!oldUser.isManagedProfile()) {
        homeActivityName = LocalServices.getService(ActivityManagerInternal.class).getHomeActivityForUser(oldUser.id);
    }
    final String[] permissions = { Manifest.permission.RECORD_AUDIO };
    List<PackageInfo> packages;
    try {
        packages = AppGlobals.getPackageManager().getPackagesHoldingPermissions(permissions, 0, oldUser.id).getList();
    } catch (RemoteException e) {
        throw new AndroidRuntimeException(e);
    }
    for (int j = packages.size() - 1; j >= 0; j--) {
        PackageInfo pkg = packages.get(j);
        // Skip system processes
        if (UserHandle.getAppId(pkg.applicationInfo.uid) < FIRST_APPLICATION_UID) {
            continue;
        }
        // Skip packages that have permission to interact across users
        if (pm.checkPermission(Manifest.permission.INTERACT_ACROSS_USERS, pkg.packageName) == PackageManager.PERMISSION_GRANTED) {
            continue;
        }
        if (homeActivityName != null && pkg.packageName.equals(homeActivityName.getPackageName()) && pkg.applicationInfo.isSystemApp()) {
            continue;
        }
        try {
            final int uid = pkg.applicationInfo.uid;
            ActivityManagerNative.getDefault().killUid(UserHandle.getAppId(uid), UserHandle.getUserId(uid), "killBackgroundUserProcessesWithAudioRecordPermission");
        } catch (RemoteException e) {
            Log.w(TAG, "Error calling killUid", e);
        }
    }
}
Also used : AndroidRuntimeException(android.util.AndroidRuntimeException) PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) ComponentName(android.content.ComponentName) RemoteException(android.os.RemoteException)

Example 18 with AndroidRuntimeException

use of android.util.AndroidRuntimeException in project android_frameworks_base by DirtyUnicorns.

the class ZenModeHelper method addAutomaticZenRule.

public String addAutomaticZenRule(AutomaticZenRule automaticZenRule, String reason) {
    if (!isSystemRule(automaticZenRule)) {
        ServiceInfo owner = getServiceInfo(automaticZenRule.getOwner());
        if (owner == null) {
            throw new IllegalArgumentException("Owner is not a condition provider service");
        }
        int ruleInstanceLimit = -1;
        if (owner.metaData != null) {
            ruleInstanceLimit = owner.metaData.getInt(ConditionProviderService.META_DATA_RULE_INSTANCE_LIMIT, -1);
        }
        if (ruleInstanceLimit > 0 && ruleInstanceLimit < (getCurrentInstanceCount(automaticZenRule.getOwner()) + 1)) {
            throw new IllegalArgumentException("Rule instance limit exceeded");
        }
    }
    ZenModeConfig newConfig;
    synchronized (mConfig) {
        if (mConfig == null) {
            throw new AndroidRuntimeException("Could not create rule");
        }
        if (DEBUG) {
            Log.d(TAG, "addAutomaticZenRule rule= " + automaticZenRule + " reason=" + reason);
        }
        newConfig = mConfig.copy();
        ZenRule rule = new ZenRule();
        populateZenRule(automaticZenRule, rule, true);
        newConfig.automaticRules.put(rule.id, rule);
        if (setConfigLocked(newConfig, reason, true)) {
            return rule.id;
        } else {
            throw new AndroidRuntimeException("Could not create rule");
        }
    }
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) AutomaticZenRule(android.app.AutomaticZenRule) ZenRule(android.service.notification.ZenModeConfig.ZenRule) AndroidRuntimeException(android.util.AndroidRuntimeException) ZenModeConfig(android.service.notification.ZenModeConfig)

Example 19 with AndroidRuntimeException

use of android.util.AndroidRuntimeException in project android_frameworks_base by DirtyUnicorns.

the class WebViewFactory method getProvider.

static WebViewFactoryProvider getProvider() {
    synchronized (sProviderLock) {
        // us honest and minimize usage of WebView internals when binding the proxy.
        if (sProviderInstance != null)
            return sProviderInstance;
        final int uid = android.os.Process.myUid();
        if (uid == android.os.Process.ROOT_UID || uid == android.os.Process.SYSTEM_UID) {
            throw new UnsupportedOperationException("For security reasons, WebView is not allowed in privileged processes");
        }
        StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
        Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.getProvider()");
        try {
            Class<WebViewFactoryProvider> providerClass = getProviderClass();
            Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "providerClass.newInstance()");
            try {
                sProviderInstance = providerClass.getConstructor(WebViewDelegate.class).newInstance(new WebViewDelegate());
                if (DEBUG)
                    Log.v(LOGTAG, "Loaded provider: " + sProviderInstance);
                return sProviderInstance;
            } catch (Exception e) {
                Log.e(LOGTAG, "error instantiating provider", e);
                throw new AndroidRuntimeException(e);
            } finally {
                Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
            }
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
            StrictMode.setThreadPolicy(oldPolicy);
        }
    }
}
Also used : StrictMode(android.os.StrictMode) AndroidRuntimeException(android.util.AndroidRuntimeException) RemoteException(android.os.RemoteException) AndroidRuntimeException(android.util.AndroidRuntimeException) IOException(java.io.IOException)

Example 20 with AndroidRuntimeException

use of android.util.AndroidRuntimeException in project android_frameworks_base by ResurrectionRemix.

the class WebViewFactory method getProvider.

static WebViewFactoryProvider getProvider() {
    synchronized (sProviderLock) {
        // us honest and minimize usage of WebView internals when binding the proxy.
        if (sProviderInstance != null)
            return sProviderInstance;
        final int uid = android.os.Process.myUid();
        if (uid == android.os.Process.ROOT_UID || uid == android.os.Process.SYSTEM_UID) {
            throw new UnsupportedOperationException("For security reasons, WebView is not allowed in privileged processes");
        }
        StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
        Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.getProvider()");
        try {
            Class<WebViewFactoryProvider> providerClass = getProviderClass();
            Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "providerClass.newInstance()");
            try {
                sProviderInstance = providerClass.getConstructor(WebViewDelegate.class).newInstance(new WebViewDelegate());
                if (DEBUG)
                    Log.v(LOGTAG, "Loaded provider: " + sProviderInstance);
                return sProviderInstance;
            } catch (Exception e) {
                Log.e(LOGTAG, "error instantiating provider", e);
                throw new AndroidRuntimeException(e);
            } finally {
                Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
            }
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
            StrictMode.setThreadPolicy(oldPolicy);
        }
    }
}
Also used : StrictMode(android.os.StrictMode) AndroidRuntimeException(android.util.AndroidRuntimeException) RemoteException(android.os.RemoteException) AndroidRuntimeException(android.util.AndroidRuntimeException) IOException(java.io.IOException)

Aggregations

AndroidRuntimeException (android.util.AndroidRuntimeException)23 RemoteException (android.os.RemoteException)10 Application (android.app.Application)5 AutomaticZenRule (android.app.AutomaticZenRule)5 ComponentName (android.content.ComponentName)5 Context (android.content.Context)5 PackageInfo (android.content.pm.PackageInfo)5 PackageManager (android.content.pm.PackageManager)5 ServiceInfo (android.content.pm.ServiceInfo)5 StrictMode (android.os.StrictMode)5 ZenModeConfig (android.service.notification.ZenModeConfig)5 ZenRule (android.service.notification.ZenModeConfig.ZenRule)5 IOException (java.io.IOException)5 List (java.util.List)1