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

Commit 1075db3c authored by LuK1337's avatar LuK1337 Committed by Arne Coucheron
Browse files

Gallery2: Get rid of packages monitor

* Oreo doesn't allow background services anymore and
  we don't really need this service anyway.

Change-Id: I919326b431b76398decdc4ed82288c2674018963
parent c2a7f929
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -359,15 +359,6 @@
            <meta-data android:name="android.appwidget.provider"
                    android:resource="@xml/widget_info" />
        </receiver>
        <receiver android:name="com.android.gallery3d.app.PackagesMonitor">
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_ADDED"/>
                <action android:name="android.intent.action.PACKAGE_REMOVED"/>
                <action android:name="android.intent.action.PACKAGE_CHANGED"/>
                <data android:scheme="package"/>
            </intent-filter>
        </receiver>
        <service android:name="com.android.gallery3d.app.PackagesMonitor$AsyncService"/>
        <service android:name="com.android.gallery3d.gadget.WidgetService"
                android:permission="android.permission.BIND_REMOTEVIEWS"/>
        <activity android:name="com.android.gallery3d.gadget.WidgetConfigure"
+0 −71
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * 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.android.gallery3d.app;

import android.app.IntentService;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.android.gallery3d.picasasource.PicasaSource;
import com.android.gallery3d.util.LightCycleHelper;

public class PackagesMonitor extends BroadcastReceiver {
    public static final String KEY_PACKAGES_VERSION  = "packages-version";

    public synchronized static int getPackagesVersion(Context context) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        return prefs.getInt(KEY_PACKAGES_VERSION, 1);
    }

    @Override
    public void onReceive(final Context context, final Intent intent) {
        intent.setClass(context, AsyncService.class);
        context.startService(intent);
    }

    public static class AsyncService extends IntentService {
        public AsyncService() {
            super("GalleryPackagesMonitorAsync");
        }

        @Override
        protected void onHandleIntent(Intent intent) {
            onReceiveAsync(this, intent);
        }
    }

    // Runs in a background thread.
    private static void onReceiveAsync(Context context, Intent intent) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

        int version = prefs.getInt(KEY_PACKAGES_VERSION, 1);
        prefs.edit().putInt(KEY_PACKAGES_VERSION, version + 1).commit();

        String action = intent.getAction();
        String packageName = intent.getData().getSchemeSpecificPart();
        if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
            PicasaSource.onPackageAdded(context, packageName);
        } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
            PicasaSource.onPackageRemoved(context, packageName);
        } else if (Intent.ACTION_PACKAGE_CHANGED.equals(action)) {
            PicasaSource.onPackageChanged(context, packageName);
        }
    }
}
+9 −3
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ import android.widget.Toast;

import org.codeaurora.gallery.R;
import com.android.gallery3d.app.GalleryActivity;
import com.android.gallery3d.app.PackagesMonitor;
import com.android.gallery3d.common.ApiHelper;
import com.android.gallery3d.data.DataManager;
import com.android.gallery3d.data.MediaItem;
@@ -75,6 +74,8 @@ public class GalleryUtils {
    private static final String KEY_CAMERA_UPDATE = "camera-update";
    private static final String KEY_HAS_CAMERA = "has-camera";

    private static final String KEY_PACKAGES_VERSION  = "packages-version";

    private static float sPixelDensity = -1f;
    private static boolean sCameraAvailableInitialized = false;
    private static boolean sCameraAvailable;
@@ -204,7 +205,7 @@ public class GalleryUtils {
    }

    public static boolean isEditorAvailable(Context context, String mimeType) {
        int version = PackagesMonitor.getPackagesVersion(context);
        int version = getPackagesVersion(context);

        String updateKey = PREFIX_PHOTO_EDITOR_UPDATE + mimeType;
        String hasKey = PREFIX_HAS_PHOTO_EDITOR + mimeType;
@@ -223,7 +224,7 @@ public class GalleryUtils {
    }

    public static boolean isAnyCameraAvailable(Context context) {
        int version = PackagesMonitor.getPackagesVersion(context);
        int version = getPackagesVersion(context);
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        if (prefs.getInt(KEY_CAMERA_UPDATE, 0) != version) {
            PackageManager packageManager = context.getPackageManager();
@@ -470,4 +471,9 @@ public class GalleryUtils {
                (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        return telephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE;
    }

    public static int getPackagesVersion(Context context) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        return prefs.getInt(KEY_PACKAGES_VERSION, 1);
    }
}
+0 −6
Original line number Diff line number Diff line
@@ -136,12 +136,6 @@ public class PicasaSource extends MediaSource {

    public static void showSignInReminder(Activity context) {/*do nothing*/}

    public static void onPackageAdded(Context context, String packageName) {/*do nothing*/}

    public static void onPackageRemoved(Context context, String packageName) {/*do nothing*/}

    public static void onPackageChanged(Context context, String packageName) {/*do nothing*/}

    public static Dialog getVersionCheckDialog(Activity activity){
        return null;
    }