Search in sources :

Example 61 with NotFoundException

use of android.content.res.Resources.NotFoundException in project android_frameworks_base by crdroidandroid.

the class WallpaperInfo method loadContextUri.

/**
     * Returns an URI that specifies a link for further context about this wallpaper.
     *
     * @param pm An instance of {@link PackageManager} to retrieve the URI.
     * @return The URI.
     */
public Uri loadContextUri(PackageManager pm) throws NotFoundException {
    if (mContextUriResource <= 0)
        throw new NotFoundException();
    String packageName = mService.resolvePackageName;
    ApplicationInfo applicationInfo = null;
    if (packageName == null) {
        packageName = mService.serviceInfo.packageName;
        applicationInfo = mService.serviceInfo.applicationInfo;
    }
    String contextUriString = pm.getText(packageName, mContextUriResource, applicationInfo).toString();
    if (contextUriString == null) {
        return null;
    }
    return Uri.parse(contextUriString);
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException)

Example 62 with NotFoundException

use of android.content.res.Resources.NotFoundException in project android_frameworks_base by crdroidandroid.

the class ApduServiceInfo method loadBanner.

public Drawable loadBanner(PackageManager pm) {
    Resources res;
    try {
        res = pm.getResourcesForApplication(mService.serviceInfo.packageName);
        Drawable banner = res.getDrawable(mBannerResourceId);
        return banner;
    } catch (NotFoundException e) {
        Log.e(TAG, "Could not load banner.");
        return null;
    } catch (NameNotFoundException e) {
        Log.e(TAG, "Could not load banner.");
        return null;
    }
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Drawable(android.graphics.drawable.Drawable) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException) Resources(android.content.res.Resources)

Example 63 with NotFoundException

use of android.content.res.Resources.NotFoundException in project android_frameworks_base by crdroidandroid.

the class AndroidPackageInfoFetcher method getStatements.

/**
     * Returns all statements that the specified package makes in its AndroidManifest.xml.
     *
     * @throws NameNotFoundException if the app is not installed on the device.
     */
public List<String> getStatements(String packageName) throws NameNotFoundException {
    PackageInfo packageInfo = mContext.getPackageManager().getPackageInfo(packageName, PackageManager.GET_META_DATA);
    ApplicationInfo appInfo = packageInfo.applicationInfo;
    if (appInfo.metaData == null) {
        return Collections.<String>emptyList();
    }
    int tokenResourceId = appInfo.metaData.getInt(ASSOCIATED_ASSETS_KEY);
    if (tokenResourceId == 0) {
        return Collections.<String>emptyList();
    }
    try {
        return Arrays.asList(mContext.getPackageManager().getResourcesForApplication(packageName).getStringArray(tokenResourceId));
    } catch (NotFoundException e) {
        return Collections.<String>emptyList();
    }
}
Also used : PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException)

Example 64 with NotFoundException

use of android.content.res.Resources.NotFoundException in project android_frameworks_base by AOSPA.

the class AndroidPackageInfoFetcher method getStatements.

/**
     * Returns all statements that the specified package makes in its AndroidManifest.xml.
     *
     * @throws NameNotFoundException if the app is not installed on the device.
     */
public List<String> getStatements(String packageName) throws NameNotFoundException {
    PackageInfo packageInfo = mContext.getPackageManager().getPackageInfo(packageName, PackageManager.GET_META_DATA);
    ApplicationInfo appInfo = packageInfo.applicationInfo;
    if (appInfo.metaData == null) {
        return Collections.<String>emptyList();
    }
    int tokenResourceId = appInfo.metaData.getInt(ASSOCIATED_ASSETS_KEY);
    if (tokenResourceId == 0) {
        return Collections.<String>emptyList();
    }
    try {
        return Arrays.asList(mContext.getPackageManager().getResourcesForApplication(packageName).getStringArray(tokenResourceId));
    } catch (NotFoundException e) {
        return Collections.<String>emptyList();
    }
}
Also used : PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException)

Example 65 with NotFoundException

use of android.content.res.Resources.NotFoundException in project android_frameworks_base by AOSPA.

the class Ringtone method playFallbackRingtone.

private boolean playFallbackRingtone() {
    if (mAudioManager.getStreamVolume(AudioAttributes.toLegacyStreamType(mAudioAttributes)) != 0) {
        int ringtoneType = RingtoneManager.getDefaultType(mUri);
        if (ringtoneType == -1 || RingtoneManager.getActualDefaultRingtoneUri(mContext, ringtoneType) != null) {
            // Default ringtone, try fallback ringtone.
            try {
                AssetFileDescriptor afd = mContext.getResources().openRawResourceFd(com.android.internal.R.raw.fallbackring);
                if (afd != null) {
                    mLocalPlayer = new MediaPlayer();
                    if (afd.getDeclaredLength() < 0) {
                        mLocalPlayer.setDataSource(afd.getFileDescriptor());
                    } else {
                        mLocalPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength());
                    }
                    mLocalPlayer.setAudioAttributes(mAudioAttributes);
                    synchronized (mPlaybackSettingsLock) {
                        applyPlaybackProperties_sync();
                    }
                    mLocalPlayer.prepare();
                    startLocalPlayer();
                    afd.close();
                    return true;
                } else {
                    Log.e(TAG, "Could not load fallback ringtone");
                }
            } catch (IOException ioe) {
                destroyLocalPlayer();
                Log.e(TAG, "Failed to open fallback ringtone");
            } catch (NotFoundException nfe) {
                Log.e(TAG, "Fallback ringtone does not exist");
            }
        } else {
            Log.w(TAG, "not playing fallback for " + mUri);
        }
    }
    return false;
}
Also used : AssetFileDescriptor(android.content.res.AssetFileDescriptor) NotFoundException(android.content.res.Resources.NotFoundException) IOException(java.io.IOException)

Aggregations

NotFoundException (android.content.res.Resources.NotFoundException)165 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)49 Resources (android.content.res.Resources)47 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)45 FileNotFoundException (java.io.FileNotFoundException)34 IOException (java.io.IOException)34 ApplicationInfo (android.content.pm.ApplicationInfo)31 File (java.io.File)30 InputStream (java.io.InputStream)28 FileInputStream (java.io.FileInputStream)20 Drawable (android.graphics.drawable.Drawable)19 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)16 Nullable (android.annotation.Nullable)15 XmlResourceParser (android.content.res.XmlResourceParser)12 SettingNotFoundException (android.provider.Settings.SettingNotFoundException)12 ArrayResourceValue (com.android.ide.common.rendering.api.ArrayResourceValue)12 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)12 NonNull (android.annotation.NonNull)10 ColorDrawable (android.graphics.drawable.ColorDrawable)10 DensityBasedResourceValue (com.android.ide.common.rendering.api.DensityBasedResourceValue)8