Home | History | Annotate | Download | only in system
      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 
     17 package com.android.car.settings.system;
     18 
     19 import android.content.Context;
     20 import android.content.Intent;
     21 import android.os.PersistableBundle;
     22 import android.telephony.CarrierConfigManager;
     23 import android.text.TextUtils;
     24 import android.view.View;
     25 
     26 import androidx.car.widget.TextListItem;
     27 
     28 import com.android.car.settings.R;
     29 
     30 
     31 /**
     32  * A LineItem that links to system update.
     33  */
     34 class SystemUpdatesListItem extends TextListItem {
     35     private final Context mContext;
     36     private final Intent mSettingsIntent;
     37 
     38     SystemUpdatesListItem(Context context, Intent settingsIntent) {
     39         super(context);
     40         mContext = context;
     41         mSettingsIntent = settingsIntent;
     42         setTitle(context.getString(R.string.system_update_settings_list_item_title));
     43         setPrimaryActionIcon(R.drawable.ic_system_update, /*useLargeIcon=*/ false);
     44         setSupplementalIcon(R.drawable.ic_chevron_right, /*showDivider=*/ false);
     45         setOnClickListener(this::onClick);
     46     }
     47 
     48     private void onClick(View view) {
     49         mContext.startActivity(mSettingsIntent);
     50 
     51         // copy what the phone setting is doing, sending out a carrier defined intent
     52         CarrierConfigManager configManager =
     53                 (CarrierConfigManager) mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
     54         PersistableBundle b = configManager.getConfig();
     55         if (b == null || !b.getBoolean(CarrierConfigManager.KEY_CI_ACTION_ON_SYS_UPDATE_BOOL)) {
     56             return;
     57         }
     58         String intentStr = b.getString(CarrierConfigManager
     59                 .KEY_CI_ACTION_ON_SYS_UPDATE_INTENT_STRING);
     60         if (!TextUtils.isEmpty(intentStr)) {
     61             String extra = b.getString(CarrierConfigManager
     62                     .KEY_CI_ACTION_ON_SYS_UPDATE_EXTRA_STRING);
     63             Intent intent = new Intent(intentStr);
     64             if (!TextUtils.isEmpty(extra)) {
     65                 String extraVal = b.getString(CarrierConfigManager
     66                         .KEY_CI_ACTION_ON_SYS_UPDATE_EXTRA_VAL_STRING);
     67                 intent.putExtra(extra, extraVal);
     68             }
     69             mContext.getApplicationContext().sendBroadcast(intent);
     70         }
     71     }
     72 }
     73