Android Open Source - HistoryCleanerPro Package Utilities






From Project

Back to project page HistoryCleanerPro.

License

The source code is released under:

Copyright (c) 2014, John Phillips All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ...

If you think the Android project HistoryCleanerPro listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright 2013 two forty four a.m. LLC <http://www.twofortyfouram.com>
 * /*from   w  w w.jav  a 2s.  c  o m*/
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * <http://www.apache.org/licenses/LICENSE-2.0>
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and limitations under the License.
 */

package com.twofortyfouram.locale;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * A simple utility class to find a package that is compatible with hosting the Locale Developer Platform.
 */
/*
 * This class is NOT part of the public Locale Developer Platform API
 */
public final class PackageUtilities
{
    /**
     * A hard-coded set of Android packages that support the Locale Developer Platform.
     */
    /*
     * This is NOT a public field and is subject to change in future releases of the Developer Platform. A
     * conscious design decision was made to use hard-coded package names, rather than dynamic discovery of
     * packages that might be compatible with hosting the Locale Developer Platform API. This is for two
     * reasons: to ensure the host is implemented correctly (hosts must pass the extensive Locale Platform
     * Host compatibility test suite) and to prevent malicious applications from crashing plug-ins by
     * providing bad values. As additional apps implement the Locale Developer Platform, their package names
     * will also be added to this list.
     */
    /*
     * Note: this is implemented as a Set<String> rather than a String[], in order to enforce immutability.
     */
    private static final Set<String> COMPATIBLE_PACKAGES = constructPackageSet();

    /**
     * @return a list wrapped in {@link Collections#unmodifiableList(List)} that represents the set of
     *         Locale-compatible packages.
     */
    private static Set<String> constructPackageSet()
    {
        final HashSet<String> packages = new HashSet<String>();

        packages.add(Constants.LOCALE_PACKAGE);

        /*
         * Note: Tasker is not 100% compatible with Locale's plug-in API, but it is close enough that these
         * packages are enabled. Tasker's known incompatibilities are documented on the Tasker website.
         */
        packages.add("net.dinglisch.android.taskerm"); //$NON-NLS-1$
        packages.add("net.dinglisch.android.tasker"); //$NON-NLS-1$
        packages.add("net.dinglisch.android.taskercupcake"); //$NON-NLS-1$

        return Collections.unmodifiableSet(packages);
    }

    /**
     * Obtains the {@code String} package name of a currently-installed package which implements the host
     * component of the Locale Developer Platform.
     * <p>
     * Note: A TOCTOU error exists, due to the fact that the package could be uninstalled at any time.
     * <p>
     * Note: If there are multiple hosts, this method will return one of them. The interface of this method
     * makes no guarantee which host will returned, nor whether that host will be consistently returned.
     * 
     * @param manager an instance of {@code PackageManager}. Cannot be null.
     * @param packageHint hint as to which package should take precedence. This parameter may be null.
     * @return {@code String} package name of a host for the Locale Developer Platform, such as
     *         "com.twofortyfouram.locale". If no such package is found, returns null.
     */
    public static String getCompatiblePackage(final PackageManager manager, final String packageHint)
    {
        /*
         * The interface for this method makes no guarantees as to which host will be returned. However the
         * implementation is more predictable.
         */

        final List<PackageInfo> installedPackages = manager.getInstalledPackages(0);

        if (COMPATIBLE_PACKAGES.contains(packageHint))
        {
            for (final PackageInfo packageInfo : installedPackages)
            {
                final String temp = packageInfo.packageName;
                if (packageHint.equals(temp))
                {
                    return temp;
                }
            }
        }

        for (final String compatiblePackageName : COMPATIBLE_PACKAGES)
        {
            if (compatiblePackageName.equals(packageHint))
            {
                continue;
            }

            for (final PackageInfo packageInfo : installedPackages)
            {
                final String temp = packageInfo.packageName;
                if (compatiblePackageName.equals(temp))
                {
                    return temp;
                }
            }
        }

        return null;
    }
}




Java Source Code List

com.ayros.historycleaner.Globals.java
com.ayros.historycleaner.ProfileAdapter.java
com.ayros.historycleaner.UIRunner.java
com.ayros.historycleaner.cleaning.CategoryList.java
com.ayros.historycleaner.cleaning.Category.java
com.ayros.historycleaner.cleaning.CleanItem.java
com.ayros.historycleaner.cleaning.CleanListener.java
com.ayros.historycleaner.cleaning.Cleaner.java
com.ayros.historycleaner.cleaning.ProfileList.java
com.ayros.historycleaner.cleaning.Profile.java
com.ayros.historycleaner.cleaning.SimpleDatabaseItem.java
com.ayros.historycleaner.cleaning.SimpleFileItem.java
com.ayros.historycleaner.cleaning.items._AdobeReader_Recent.java
com.ayros.historycleaner.cleaning.items._FirefoxBeta_Cache.java
com.ayros.historycleaner.cleaning.items._FirefoxBeta_Cookies.java
com.ayros.historycleaner.cleaning.items._FirefoxBeta_History.java
com.ayros.historycleaner.cleaning.items._FirefoxBeta_LocalStorage.java
com.ayros.historycleaner.cleaning.items._FirefoxBeta_OpenTabs.java
com.ayros.historycleaner.cleaning.items._Firefox_Cache.java
com.ayros.historycleaner.cleaning.items._Firefox_Cookies.java
com.ayros.historycleaner.cleaning.items._Firefox_History.java
com.ayros.historycleaner.cleaning.items._Firefox_LocalStorage.java
com.ayros.historycleaner.cleaning.items._Firefox_OpenTabs.java
com.ayros.historycleaner.cleaning.items._ONEBrowser_Cache.java
com.ayros.historycleaner.cleaning.items._ONEBrowser_LocalStorage.java
com.ayros.historycleaner.cleaning.items._System_BrowserHistory.java
com.ayros.historycleaner.cleaning.items._System_Cache.java
com.ayros.historycleaner.cleaning.items._System_Clipboard.java
com.ayros.historycleaner.cleaning.items._System_FrequentContacts.java
com.ayros.historycleaner.cleaning.items._System_RecentCalls.java
com.ayros.historycleaner.cleaning.items._System_SMS.java
com.ayros.historycleaner.helpers.DBHelper.java
com.ayros.historycleaner.helpers.DatabaseModifier.java
com.ayros.historycleaner.helpers.Helper.java
com.ayros.historycleaner.helpers.Logger.java
com.ayros.historycleaner.helpers.PrefsModifier.java
com.ayros.historycleaner.helpers.RootHelper.java
com.ayros.historycleaner.helpers.XML.java
com.ayros.historycleaner.locale.Constants.java
com.ayros.historycleaner.locale.bundle.BundleScrubber.java
com.ayros.historycleaner.locale.bundle.PluginBundleManager.java
com.ayros.historycleaner.locale.receiver.FireReceiver.java
com.ayros.historycleaner.locale.ui.AbstractPluginActivity.java
com.ayros.historycleaner.locale.ui.EditPluginActivity.java
com.ayros.historycleaner.ui.CleanFragment.java
com.ayros.historycleaner.ui.DataViewActivity.java
com.ayros.historycleaner.ui.HelpActivity.java
com.ayros.historycleaner.ui.MainActivity.java
com.ayros.historycleaner.ui.OnProfileUpdated.java
com.ayros.historycleaner.ui.ProfileFragment.java
com.ayros.historycleaner.ui.ShortcutActivity.java
com.ayros.historycleaner.ui.ShortcutCleanActivity.java
com.twofortyfouram.locale.BreadCrumber.java
com.twofortyfouram.locale.Constants.java
com.twofortyfouram.locale.Intent.java
com.twofortyfouram.locale.PackageUtilities.java