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

Commit f435a6d8 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge changes I24babd8a,I3f306996 into main am: efbf0769 am: 123bfbca

parents fcf2019a 123bfbca
Loading
Loading
Loading
Loading
+8 −22
Original line number Diff line number Diff line
@@ -26,8 +26,6 @@ import android.util.Log;
public class BluetoothMapAccountItem implements Comparable<BluetoothMapAccountItem> {
    private static final String TAG = "BluetoothMapAccountItem";

    private static final boolean V = BluetoothMapService.VERBOSE;

    protected boolean mIsChecked;
    private final String mName;
    private final String mPackageName;
@@ -96,41 +94,29 @@ public class BluetoothMapAccountItem implements Comparable<BluetoothMapAccountIt
    public int compareTo(BluetoothMapAccountItem other) {

        if (!other.mId.equals(this.mId)) {
            if (V) {
                Log.d(TAG, "Wrong id : " + this.mId + " vs " + other.mId);
            }
            Log.v(TAG, "Wrong id : " + this.mId + " vs " + other.mId);
            return -1;
        }
        if (!other.mName.equals(this.mName)) {
            if (V) {
                Log.d(TAG, "Wrong name : " + this.mName + " vs " + other.mName);
            }
            Log.v(TAG, "Wrong name : " + this.mName + " vs " + other.mName);
            return -1;
        }
        if (!other.mPackageName.equals(this.mPackageName)) {
            if (V) {
                Log.d(TAG,
            Log.v(TAG,
                    "Wrong packageName : " + this.mPackageName + " vs " + other.mPackageName);
            }
            return -1;
        }
        if (!other.mProviderAuthority.equals(this.mProviderAuthority)) {
            if (V) {
                Log.d(TAG, "Wrong providerName : " + this.mProviderAuthority + " vs "
            Log.v(TAG, "Wrong providerName : " + this.mProviderAuthority + " vs "
                    + other.mProviderAuthority);
            }
            return -1;
        }
        if (other.mIsChecked != this.mIsChecked) {
            if (V) {
                Log.d(TAG, "Wrong isChecked : " + this.mIsChecked + " vs " + other.mIsChecked);
            }
            Log.v(TAG, "Wrong isChecked : " + this.mIsChecked + " vs " + other.mIsChecked);
            return -1;
        }
        if (!other.mType.equals(this.mType)) {
            if (V) {
                Log.d(TAG, "Wrong appType : " + this.mType + " vs " + other.mType);
            }
            Log.v(TAG, "Wrong appType : " + this.mType + " vs " + other.mType);
            return -1;
        }
        return 0;
+18 −40
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ import java.util.Objects;
// Next tag value for ContentProfileErrorReportUtils.report(): 1
public class BluetoothMapAccountLoader {
    private static final String TAG = "BluetoothMapAccountLoader";
    private static final boolean D = BluetoothMapService.DEBUG;

    private Context mContext = null;
    private PackageManager mPackageManager = null;
    private ContentResolver mResolver;
@@ -82,17 +82,13 @@ public class BluetoothMapAccountLoader {
            List<ResolveInfo> resInfos =
                    mPackageManager.queryIntentContentProviders(searchIntent, 0);
            if (resInfos != null) {
                if (D) {
                Log.d(TAG, "Found " + resInfos.size() + " application(s) with intent "
                        + searchIntent.getAction());
                }
                BluetoothMapUtils.TYPE msgType = (Objects.equals(searchIntent.getAction(),
                        BluetoothMapContract.PROVIDER_INTERFACE_EMAIL))
                        ? BluetoothMapUtils.TYPE.EMAIL : BluetoothMapUtils.TYPE.IM;
                for (ResolveInfo rInfo : resInfos) {
                    if (D) {
                    Log.d(TAG, "ResolveInfo " + rInfo.toString());
                    }
                    // We cannot rely on apps that have been force-stopped in the
                    // application settings menu.
                    if ((rInfo.providerInfo.applicationInfo.flags & ApplicationInfo.FLAG_STOPPED)
@@ -115,18 +111,14 @@ public class BluetoothMapAccountLoader {
                            }
                        }
                    } else {
                        if (D) {
                        Log.d(TAG, "Ignoring force-stopped authority "
                                + rInfo.providerInfo.authority + "\n");
                    }
                }
                }
            } else {
                if (D) {
                Log.d(TAG, "Found no applications");
            }
        }
        }
        return groups;
    }

@@ -135,11 +127,9 @@ public class BluetoothMapAccountLoader {
        String provider = rInfo.providerInfo.authority;
        if (provider != null) {
            String name = rInfo.loadLabel(mPackageManager).toString();
            if (D) {
            Log.d(TAG,
                    rInfo.providerInfo.packageName + " - " + name + " - meta-data(provider = "
                            + provider + ")\n");
            }
            BluetoothMapAccountItem app =
                    BluetoothMapAccountItem.create("0", name, rInfo.providerInfo.packageName,
                            provider, (!includeIcon) ? null : rInfo.loadIcon(mPackageManager),
@@ -157,9 +147,7 @@ public class BluetoothMapAccountLoader {
     */
    public ArrayList<BluetoothMapAccountItem> parseAccounts(BluetoothMapAccountItem app) {
        Cursor c = null;
        if (D) {
        Log.d(TAG, "Finding accounts for app " + app.getPackageName());
        }
        ArrayList<BluetoothMapAccountItem> children = new ArrayList<BluetoothMapAccountItem>();
        // Get the list of accounts from the email apps content resolver (if possible)
        mResolver = mContext.getContentResolver();
@@ -192,10 +180,8 @@ public class BluetoothMapAccountLoader {
                    BluetoothProtoEnums.BLUETOOTH_MAP_ACCOUNT_LOADER,
                    BluetoothStatsLog.BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                    0);
            if (D) {
            Log.d(TAG, "Could not establish ContentProviderClient for " + app.getPackageName()
                    + " - returning empty account list");
            }
            return children;
        } finally {
            if (mProviderClient != null) {
@@ -213,19 +199,15 @@ public class BluetoothMapAccountLoader {
            int uciPreIndex =
                    c.getColumnIndex(BluetoothMapContract.AccountColumns.ACCOUNT_UCI_PREFIX);
            while (c.moveToNext()) {
                if (D) {
                Log.d(TAG, "Adding account " + c.getString(dispNameIndex) + " with ID " + String
                        .valueOf(c.getInt(idIndex)));
                }
                String uci = null;
                String uciPrefix = null;
                if (app.getType() == TYPE.IM) {
                    uci = c.getString(uciIndex);
                    uciPrefix = c.getString(uciPreIndex);
                    if (D) {
                    Log.d(TAG, "   Account UCI " + uci);
                }
                }

                BluetoothMapAccountItem child =
                        BluetoothMapAccountItem.create(String.valueOf((c.getInt(idIndex))),
@@ -243,10 +225,8 @@ public class BluetoothMapAccountLoader {
            }
            c.close();
        } else {
            if (D) {
            Log.d(TAG, "query failed");
        }
        }
        return children;
    }

@@ -257,9 +237,7 @@ public class BluetoothMapAccountLoader {
     * @return number of enabled accounts
     */
    public int getAccountsEnabledCount() {
        if (D) {
        Log.d(TAG, "Enabled Accounts count:" + mAccountsEnabledCount);
        }
        return mAccountsEnabledCount;
    }

+44 −94
Original line number Diff line number Diff line
@@ -42,8 +42,6 @@ public class BluetoothMapAppObserver {

    private static final String TAG = "BluetoothMapAppObserver";

    private static final boolean D = BluetoothMapService.DEBUG;
    private static final boolean V = BluetoothMapService.VERBOSE;
    /*  */
    private LinkedHashMap<BluetoothMapAccountItem, ArrayList<BluetoothMapAccountItem>> mFullList;
    private LinkedHashMap<String, ContentObserver> mObserverMap =
@@ -68,32 +66,22 @@ public class BluetoothMapAppObserver {


    private BluetoothMapAccountItem getApp(String authoritiesName) {
        if (V) {
            Log.d(TAG, "getApp(): Looking for " + authoritiesName);
        }
        Log.v(TAG, "getApp(): Looking for " + authoritiesName);
        for (BluetoothMapAccountItem app : mFullList.keySet()) {
            if (V) {
                Log.d(TAG, "  Comparing: " + app.getProviderAuthority());
            }
            Log.v(TAG, "  Comparing: " + app.getProviderAuthority());
            if (app.getProviderAuthority().equals(authoritiesName)) {
                if (V) {
                    Log.d(TAG, "  found " + app.mBase_uri_no_account);
                }
                Log.v(TAG, "  found " + app.mBase_uri_no_account);
                return app;
            }
        }
        if (V) {
            Log.d(TAG, "  NOT FOUND!");
        }
        Log.v(TAG, "  NOT FOUND!");
        return null;
    }

    private void handleAccountChanges(String packageNameWithProvider) {

        if (D) {
        Log.d(TAG, "handleAccountChanges (packageNameWithProvider: " + packageNameWithProvider
                + "\n");
        }
        //String packageName = packageNameWithProvider.replaceFirst("\\.[^\\.]+$", "");
        BluetoothMapAccountItem app = getApp(packageNameWithProvider);
        if (app != null) {
@@ -121,9 +109,7 @@ public class BluetoothMapAppObserver {
                            // Name Changed and the acc is visible - Change Name in SDP record
                            mMapService.updateMasInstances(
                                    BluetoothMapService.UPDATE_MAS_INSTANCES_ACCOUNT_RENAMED);
                            if (V) {
                                Log.d(TAG, "    UPDATE_MAS_INSTANCES_ACCOUNT_RENAMED");
                            }
                            Log.v(TAG, "    UPDATE_MAS_INSTANCES_ACCOUNT_RENAMED");
                        }
                        if (newAcc.mIsChecked != oldAcc.mIsChecked) {
                            // Visibility changed
@@ -131,20 +117,16 @@ public class BluetoothMapAppObserver {
                                // account added - create SDP record
                                mMapService.updateMasInstances(
                                        BluetoothMapService.UPDATE_MAS_INSTANCES_ACCOUNT_ADDED);
                                if (V) {
                                    Log.d(TAG, "UPDATE_MAS_INSTANCES_ACCOUNT_ADDED "
                                Log.v(TAG, "UPDATE_MAS_INSTANCES_ACCOUNT_ADDED "
                                        + "isChecked changed");
                                }
                            } else {
                                // account removed - remove SDP record
                                mMapService.updateMasInstances(
                                        BluetoothMapService.UPDATE_MAS_INSTANCES_ACCOUNT_REMOVED);
                                if (V) {
                                    Log.d(TAG, "    UPDATE_MAS_INSTANCES_ACCOUNT_REMOVED "
                                Log.v(TAG, "    UPDATE_MAS_INSTANCES_ACCOUNT_REMOVED "
                                        + "isChecked changed");
                            }
                        }
                        }
                        break;
                    }
                }
@@ -153,17 +135,13 @@ public class BluetoothMapAppObserver {
            for (BluetoothMapAccountItem removedAcc : removedAccountList) {
                mMapService.updateMasInstances(
                        BluetoothMapService.UPDATE_MAS_INSTANCES_ACCOUNT_REMOVED);
                if (V) {
                    Log.d(TAG, "    UPDATE_MAS_INSTANCES_ACCOUNT_REMOVED " + removedAcc);
                }
                Log.v(TAG, "    UPDATE_MAS_INSTANCES_ACCOUNT_REMOVED " + removedAcc);
            }
            // Notify on any new accounts
            for (BluetoothMapAccountItem addedAcc : addedAccountList) {
                mMapService.updateMasInstances(
                        BluetoothMapService.UPDATE_MAS_INSTANCES_ACCOUNT_ADDED);
                if (V) {
                    Log.d(TAG, "    UPDATE_MAS_INSTANCES_ACCOUNT_ADDED " + addedAcc);
                }
                Log.v(TAG, "    UPDATE_MAS_INSTANCES_ACCOUNT_ADDED " + addedAcc);
            }

        } else {
@@ -184,9 +162,7 @@ public class BluetoothMapAppObserver {
     */
    public void registerObserver(BluetoothMapAccountItem app) {
        Uri uri = BluetoothMapContract.buildAccountUri(app.getProviderAuthority());
        if (V) {
            Log.d(TAG, "registerObserver for URI " + uri.toString() + "\n");
        }
        Log.v(TAG, "registerObserver for URI " + uri.toString() + "\n");
        ContentObserver observer =
                new ContentObserver(null) {
                    @Override
@@ -196,8 +172,7 @@ public class BluetoothMapAppObserver {

                    @Override
                    public void onChange(boolean selfChange, Uri uri) {
                        if (V) {
                            Log.d(
                        Log.v(
                                TAG,
                                "onChange on thread: "
                                        + Thread.currentThread().getId()
@@ -205,7 +180,6 @@ public class BluetoothMapAppObserver {
                                        + uri
                                        + " selfchange: "
                                        + selfChange);
                        }
                        if (uri != null) {
                            handleAccountChanges(uri.getHost());
                        } else {
@@ -226,35 +200,27 @@ public class BluetoothMapAppObserver {

    public void unregisterObserver(BluetoothMapAccountItem app) {
        Uri uri = BluetoothMapContract.buildAccountUri(app.getProviderAuthority());
        if (V) {
            Log.d(TAG, "unregisterObserver(" + uri.toString() + ")\n");
        }
        Log.v(TAG, "unregisterObserver(" + uri.toString() + ")\n");
        mResolver.unregisterContentObserver(mObserverMap.get(uri.toString()));
        mObserverMap.remove(uri.toString());
    }

    private void initObservers() {
        if (D) {
        Log.d(TAG, "initObservers()");
        }
        for (BluetoothMapAccountItem app : mFullList.keySet()) {
            registerObserver(app);
        }
    }

    private void deinitObservers() {
        if (D) {
        Log.d(TAG, "deinitObservers()");
        }
        for (BluetoothMapAccountItem app : mFullList.keySet()) {
            unregisterObserver(app);
        }
    }

    private void createReceiver() {
        if (D) {
        Log.d(TAG, "createReceiver()\n");
        }
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
        intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
@@ -264,17 +230,13 @@ public class BluetoothMapAppObserver {
                new BroadcastReceiver() {
                    @Override
                    public void onReceive(Context context, Intent intent) {
                        if (D) {
                        Log.d(TAG, "onReceive\n");
                        }
                        String action = intent.getAction();

                        if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
                            Uri data = intent.getData();
                            String packageName = data.getEncodedSchemeSpecificPart();
                            if (D) {
                            Log.d(TAG, "The installed package is: " + packageName);
                            }

                            BluetoothMapUtils.TYPE msgType = BluetoothMapUtils.TYPE.NONE;
                            ResolveInfo resolveInfo = null;
@@ -294,14 +256,12 @@ public class BluetoothMapAppObserver {
                                        mPackageManager.queryIntentContentProviders(
                                                searchIntent, 0);
                                if (resInfos != null) {
                                    if (D) {
                                    Log.d(
                                            TAG,
                                            "Found "
                                                    + resInfos.size()
                                                    + " application(s) with intent "
                                                    + searchIntent.getAction());
                                    }
                                    for (ResolveInfo rInfo : resInfos) {
                                        if (rInfo != null) {
                                            // Find out if package contain Bluetooth MAP support
@@ -327,14 +287,12 @@ public class BluetoothMapAppObserver {
                            }
                            // if application found with Bluetooth MAP support add to list
                            if (resolveInfo != null) {
                                if (D) {
                                Log.d(
                                        TAG,
                                        "Found "
                                                + resolveInfo.providerInfo.packageName
                                                + " application of type "
                                                + msgType);
                                }
                                BluetoothMapAccountItem app =
                                        mLoader.createAppItem(resolveInfo, false, msgType);
                                if (app != null) {
@@ -349,9 +307,7 @@ public class BluetoothMapAppObserver {
                        } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
                            Uri data = intent.getData();
                            String packageName = data.getEncodedSchemeSpecificPart();
                            if (D) {
                            Log.d(TAG, "The removed package is: " + packageName);
                            }
                            BluetoothMapAccountItem app = getApp(packageName);
                            /* Find the object and remove from fullList */
                            if (app != null) {
@@ -377,9 +333,7 @@ public class BluetoothMapAppObserver {
    }

    private void removeReceiver() {
        if (D) {
        Log.d(TAG, "removeReceiver()\n");
        }
        if (mRegisteredReceiver) {
            try {
                mRegisteredReceiver = false;
@@ -401,9 +355,7 @@ public class BluetoothMapAppObserver {
     * @return Arraylist<BluetoothMapAccountItem> containing all enabled accounts
     */
    public ArrayList<BluetoothMapAccountItem> getEnabledAccountItems() {
        if (D) {
        Log.d(TAG, "getEnabledAccountItems()\n");
        }
        ArrayList<BluetoothMapAccountItem> list = new ArrayList<BluetoothMapAccountItem>();
        for (BluetoothMapAccountItem app : mFullList.keySet()) {
            if (app != null) {
@@ -440,9 +392,7 @@ public class BluetoothMapAppObserver {
     * @return Arraylist<BluetoothMapAccountItem> containing all accounts
     */
    public ArrayList<BluetoothMapAccountItem> getAllAccountItems() {
        if (D) {
        Log.d(TAG, "getAllAccountItems()\n");
        }
        ArrayList<BluetoothMapAccountItem> list = new ArrayList<BluetoothMapAccountItem>();
        for (BluetoothMapAccountItem app : mFullList.keySet()) {
            ArrayList<BluetoothMapAccountItem> accountList = mFullList.get(app);
+157 −410

File changed.

Preview size limit exceeded, changes collapsed.

+118 −289

File changed.

Preview size limit exceeded, changes collapsed.

Loading