1 /* 2 * Copyright (C) 2018 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.settings.slices; 18 19 import android.content.Context; 20 import android.net.Uri; 21 import android.os.SystemClock; 22 23 import com.android.settings.network.telephony.Enhanced4gLteSliceHelper; 24 import com.android.settings.wifi.calling.WifiCallingSliceHelper; 25 import com.android.settingslib.utils.ThreadUtils; 26 27 /** 28 * Manages Slices in Settings. 29 */ 30 public class SlicesFeatureProviderImpl implements SlicesFeatureProvider { 31 32 private long mUiSessionToken; 33 private SlicesIndexer mSlicesIndexer; 34 private SliceDataConverter mSliceDataConverter; 35 36 @Override getSliceDataConverter(Context context)37 public SliceDataConverter getSliceDataConverter(Context context) { 38 if (mSliceDataConverter == null) { 39 mSliceDataConverter = new SliceDataConverter(context.getApplicationContext()); 40 } 41 return mSliceDataConverter; 42 } 43 44 @Override newUiSession()45 public void newUiSession() { 46 mUiSessionToken = SystemClock.elapsedRealtime(); 47 } 48 49 @Override getUiSessionToken()50 public long getUiSessionToken() { 51 return mUiSessionToken; 52 } 53 54 @Override indexSliceDataAsync(Context context)55 public void indexSliceDataAsync(Context context) { 56 SlicesIndexer indexer = getSliceIndexer(context); 57 ThreadUtils.postOnBackgroundThread(indexer); 58 } 59 60 @Override indexSliceData(Context context)61 public void indexSliceData(Context context) { 62 SlicesIndexer indexer = getSliceIndexer(context); 63 indexer.indexSliceData(); 64 } 65 66 @Override getNewWifiCallingSliceHelper(Context context)67 public WifiCallingSliceHelper getNewWifiCallingSliceHelper(Context context) { 68 return new WifiCallingSliceHelper(context); 69 } 70 71 @Override getNewEnhanced4gLteSliceHelper(Context context)72 public Enhanced4gLteSliceHelper getNewEnhanced4gLteSliceHelper(Context context) { 73 return new Enhanced4gLteSliceHelper(context); 74 } 75 76 @Override getSliceableFromUri(Context context, Uri uri)77 public CustomSliceable getSliceableFromUri(Context context, Uri uri) { 78 final Uri newUri = CustomSliceRegistry.removeParameterFromUri(uri); 79 final Class clazz = CustomSliceRegistry.getSliceClassByUri(newUri); 80 if (clazz == null) { 81 throw new IllegalArgumentException("No Slice found for uri: " + uri); 82 } 83 84 final CustomSliceable sliceable = CustomSliceable.createInstance(context, clazz); 85 return sliceable; 86 } 87 getSliceIndexer(Context context)88 private SlicesIndexer getSliceIndexer(Context context) { 89 if (mSlicesIndexer == null) { 90 mSlicesIndexer = new SlicesIndexer(context.getApplicationContext()); 91 } 92 return mSlicesIndexer; 93 } 94 } 95