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

Commit 2ca0e7b2 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "settings_injection_v2"

* changes:
  [SettingsLib] Support pure switch of inline toggle of Settings Injection v2
  Add new interfaces for inline toggle of Settings Injection v2
parents 7e0ad065 499a579c
Loading
Loading
Loading
Loading
+14 −9
Original line number Diff line number Diff line
@@ -52,15 +52,6 @@ public class ActivityTile extends Tile {
        return getPackageName() + "/" + getComponentName();
    }

    @Override
    protected CharSequence getComponentLabel(Context context) {
        final PackageManager pm = context.getPackageManager();
        final ComponentInfo info = getComponentInfo(context);
        return info == null
                ? null
                : info.loadLabel(pm);
    }

    @Override
    protected ComponentInfo getComponentInfo(Context context) {
        if (mComponentInfo == null) {
@@ -78,4 +69,18 @@ public class ActivityTile extends Tile {
        }
        return mComponentInfo;
    }

    @Override
    protected CharSequence getComponentLabel(Context context) {
        final PackageManager pm = context.getPackageManager();
        final ComponentInfo info = getComponentInfo(context);
        return info == null
                ? null
                : info.loadLabel(pm);
    }

    @Override
    protected int getComponentIcon(ComponentInfo componentInfo) {
        return componentInfo.icon;
    }
}
+23 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.settingslib.drawer;

/** Interface for {@link SwitchController} whose instances support dynamic summary */
public interface DynamicSummary {
    /** @return the dynamic summary text */
    String getDynamicSummary();
}
+23 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.settingslib.drawer;

/** Interface for {@link SwitchController} whose instances support dynamic title */
public interface DynamicTitle {
    /** @return the dynamic title text */
    String getDynamicTitle();
}
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.settingslib.drawer;

import android.os.Bundle;

/**
 *  Interface for {@link SwitchController} whose instances support icon provided from the content
 *  provider
 */
public interface ProviderIcon {
    /**
     * @return the bundle of icon info including {@link TileUtils#EXTRA_PREFERENCE_ICON_PACKAGE} and
     * {@link TileUtils#META_DATA_PREFERENCE_ICON}.
     */
    Bundle getProviderIcon();
}
+105 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.settingslib.drawer;

import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_KEYHINT;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ComponentInfo;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.os.Parcel;
import android.util.Log;

import java.util.List;
import java.util.Objects;

/**
 * Description of a single dashboard tile which is generated from a content provider.
 */
public class ProviderTile extends Tile {
    private static final String TAG = "ProviderTile";

    private static final boolean DEBUG_TIMING = false;

    private String mAuthority;
    private String mKey;

    public ProviderTile(ComponentInfo info, String category, Bundle metaData) {
        super(info, category);
        setMetaData(metaData);
        mAuthority = ((ProviderInfo) info).authority;
        mKey = metaData.getString(META_DATA_PREFERENCE_KEYHINT);
    }

    ProviderTile(Parcel in) {
        super(in);
        mAuthority = ((ProviderInfo) mComponentInfo).authority;
        mKey = getMetaData().getString(META_DATA_PREFERENCE_KEYHINT);
    }

    @Override
    public int getId() {
        return Objects.hash(mAuthority, mKey);
    }

    @Override
    public String getDescription() {
        return mAuthority + "/" + mKey;
    }

    @Override
    protected ComponentInfo getComponentInfo(Context context) {
        if (mComponentInfo == null) {
            final long startTime = System.currentTimeMillis();
            final PackageManager pm = context.getApplicationContext().getPackageManager();
            final Intent intent = getIntent();
            final List<ResolveInfo> infoList =
                    pm.queryIntentContentProviders(intent, 0 /* flags */);
            if (infoList != null && !infoList.isEmpty()) {
                final ProviderInfo providerInfo = infoList.get(0).providerInfo;
                mComponentInfo = providerInfo;
                setMetaData(TileUtils.getSwitchDataFromProvider(context, providerInfo.authority,
                        mKey));
            } else {
                Log.e(TAG, "Cannot find package info for "
                        + intent.getComponent().flattenToString());
            }

            if (DEBUG_TIMING) {
                Log.d(TAG, "getComponentInfo took "
                        + (System.currentTimeMillis() - startTime) + " ms");
            }
        }
        return mComponentInfo;
    }

    @Override
    protected CharSequence getComponentLabel(Context context) {
        // Getting provider label for a tile title isn't supported.
        return null;
    }

    @Override
    protected int getComponentIcon(ComponentInfo info) {
        // Getting provider icon for a tile title isn't supported.
        return 0;
    }
}
Loading