AppInstallerInfoPreferenceController.java revision b5c651c9399aa53e0bef296a265a47c825fe12b2
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.settings.applications.appinfo;
18
19import android.content.Context;
20import android.content.Intent;
21import android.os.UserManager;
22import android.support.v7.preference.Preference;
23
24import com.android.settings.R;
25import com.android.settings.Utils;
26import com.android.settings.applications.AppStoreUtil;
27import com.android.settingslib.applications.AppUtils;
28
29public class AppInstallerInfoPreferenceController extends AppInfoPreferenceControllerBase {
30
31    private String mPackageName;
32    private String mInstallerPackage;
33    private CharSequence mInstallerLabel;
34
35    public AppInstallerInfoPreferenceController(Context context, String key) {
36        super(context, key);
37    }
38
39    @Override
40    public int getAvailabilityStatus() {
41        if (UserManager.get(mContext).isManagedProfile()) {
42            return DISABLED_FOR_USER;
43        }
44        return mInstallerLabel != null ? AVAILABLE : DISABLED_FOR_USER;
45    }
46
47    @Override
48    public void updateState(Preference preference) {
49        final int detailsStringId = AppUtils.isInstant(mParent.getPackageInfo().applicationInfo)
50                ? R.string.instant_app_details_summary
51                : R.string.app_install_details_summary;
52        preference.setSummary(mContext.getString(detailsStringId, mInstallerLabel));
53
54        Intent intent = AppStoreUtil.getAppStoreLink(mContext, mInstallerPackage, mPackageName);
55        if (intent != null) {
56            preference.setIntent(intent);
57        } else {
58            preference.setEnabled(false);
59        }
60    }
61
62    public void setPackageName(String packageName) {
63        mPackageName = packageName;
64        mInstallerPackage = AppStoreUtil.getInstallerPackageName(mContext, mPackageName);
65        mInstallerLabel = Utils.getApplicationLabel(mContext, mInstallerPackage);
66    }
67}
68