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

Commit 453fe2fb authored by Wesley.CW Wang's avatar Wesley.CW Wang
Browse files

Hide clock option when there is only 1 option[1/2]

- Not to add clock option(tab) to home page when there is only 1 option
- By default, there should be only 1 clock(Default clock) build-in with device, additional clock content will be provided by another apk, if can not find that apk means we only have 1 clock option, then hide the clock tab

Bug: 146530441
Test: Need work with ag/10361873, modify the mk file to build up additional clock content, then check the Picker app will display Clock tab or not.

Change-Id: Ie64e6f0074869792a956d6b47e4f483a2bbd531f
parent a35ce9d3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
-->
<resources>
    <string name="themes_stub_package" translatable="false"/>
    <string name="clocks_stub_package" translatable="false"/>
    <!-- Authority of a provider in System UI that will provide preview info for available clockfaces. -->
    <string name="clocks_provider_authority" translatable="false">com.android.keyguard.clock</string>

+18 −1
Original line number Diff line number Diff line
@@ -2,7 +2,9 @@ package com.android.customization.model.clock;

import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ProviderInfo;
import android.database.Cursor;
import android.net.Uri;
@@ -25,6 +27,7 @@ public class ContentProviderClockProvider implements ClockProvider {
    private final Context mContext;
    private final ProviderInfo mProviderInfo;
    private List<Clockface> mClocks;
    private boolean mClockContentAvailable;

    public ContentProviderClockProvider(Context context) {
        mContext = context;
@@ -33,11 +36,25 @@ public class ContentProviderClockProvider implements ClockProvider {
        mProviderInfo = TextUtils.isEmpty(providerAuthority) ? null
                : mContext.getPackageManager().resolveContentProvider(providerAuthority,
                        PackageManager.MATCH_SYSTEM_ONLY);

        if (TextUtils.isEmpty(mContext.getString(R.string.clocks_stub_package))) {
            mClockContentAvailable = false;
        } else {
            try {
                ApplicationInfo applicationInfo = mContext.getPackageManager().getApplicationInfo(
                        mContext.getString(R.string.clocks_stub_package),
                        PackageManager.MATCH_SYSTEM_ONLY);
                mClockContentAvailable = applicationInfo != null;
            } catch (NameNotFoundException e) {
                mClockContentAvailable = false;
            }
        }
    }

    @Override
    public boolean isAvailable() {
        return mProviderInfo != null && (mClocks == null || !mClocks.isEmpty());
        return mProviderInfo != null && mClockContentAvailable
                && (mClocks == null || !mClocks.isEmpty());
    }

    @Override