Search in sources :

Example 6 with TvInputInfo

use of android.media.tv.TvInputInfo in project platform_frameworks_base by android.

the class TvInputManagerService method buildTvInputListLocked.

private void buildTvInputListLocked(int userId, String[] updatedPackages) {
    UserState userState = getOrCreateUserStateLocked(userId);
    userState.packageSet.clear();
    if (DEBUG)
        Slog.d(TAG, "buildTvInputList");
    PackageManager pm = mContext.getPackageManager();
    List<ResolveInfo> services = pm.queryIntentServicesAsUser(new Intent(TvInputService.SERVICE_INTERFACE), PackageManager.GET_SERVICES | PackageManager.GET_META_DATA, userId);
    List<TvInputInfo> inputList = new ArrayList<>();
    for (ResolveInfo ri : services) {
        ServiceInfo si = ri.serviceInfo;
        if (!android.Manifest.permission.BIND_TV_INPUT.equals(si.permission)) {
            Slog.w(TAG, "Skipping TV input " + si.name + ": it does not require the permission " + android.Manifest.permission.BIND_TV_INPUT);
            continue;
        }
        ComponentName component = new ComponentName(si.packageName, si.name);
        if (hasHardwarePermission(pm, component)) {
            ServiceState serviceState = userState.serviceStateMap.get(component);
            if (serviceState == null) {
                // New hardware input found. Create a new ServiceState and connect to the
                // service to populate the hardware list.
                serviceState = new ServiceState(component, userId);
                userState.serviceStateMap.put(component, serviceState);
                updateServiceConnectionLocked(component, userId);
            } else {
                inputList.addAll(serviceState.hardwareInputList);
            }
        } else {
            try {
                TvInputInfo info = new TvInputInfo.Builder(mContext, ri).build();
                inputList.add(info);
            } catch (Exception e) {
                Slog.e(TAG, "failed to load TV input " + si.name, e);
                continue;
            }
        }
        userState.packageSet.add(si.packageName);
    }
    Map<String, TvInputState> inputMap = new HashMap<>();
    for (TvInputInfo info : inputList) {
        if (DEBUG) {
            Slog.d(TAG, "add " + info.getId());
        }
        TvInputState inputState = userState.inputMap.get(info.getId());
        if (inputState == null) {
            inputState = new TvInputState();
        }
        inputState.info = info;
        inputMap.put(info.getId(), inputState);
    }
    for (String inputId : inputMap.keySet()) {
        if (!userState.inputMap.containsKey(inputId)) {
            notifyInputAddedLocked(userState, inputId);
        } else if (updatedPackages != null) {
            // Notify the package updates
            ComponentName component = inputMap.get(inputId).info.getComponent();
            for (String updatedPackage : updatedPackages) {
                if (component.getPackageName().equals(updatedPackage)) {
                    updateServiceConnectionLocked(component, userId);
                    notifyInputUpdatedLocked(userState, inputId);
                    break;
                }
            }
        }
    }
    for (String inputId : userState.inputMap.keySet()) {
        if (!inputMap.containsKey(inputId)) {
            TvInputInfo info = userState.inputMap.get(inputId).info;
            ServiceState serviceState = userState.serviceStateMap.get(info.getComponent());
            if (serviceState != null) {
                abortPendingCreateSessionRequestsLocked(serviceState, inputId, userId);
            }
            notifyInputRemovedLocked(userState, inputId);
        }
    }
    userState.inputMap.clear();
    userState.inputMap = inputMap;
}
Also used : HashMap(java.util.HashMap) TvInputInfo(android.media.tv.TvInputInfo) ArrayList(java.util.ArrayList) Intent(android.content.Intent) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) OperationApplicationException(android.content.OperationApplicationException) ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) PackageManager(android.content.pm.PackageManager) ComponentName(android.content.ComponentName)

Example 7 with TvInputInfo

use of android.media.tv.TvInputInfo in project android_frameworks_base by DirtyUnicorns.

the class TvInputManagerService method buildTvInputListLocked.

private void buildTvInputListLocked(int userId, String[] updatedPackages) {
    UserState userState = getOrCreateUserStateLocked(userId);
    userState.packageSet.clear();
    if (DEBUG)
        Slog.d(TAG, "buildTvInputList");
    PackageManager pm = mContext.getPackageManager();
    List<ResolveInfo> services = pm.queryIntentServicesAsUser(new Intent(TvInputService.SERVICE_INTERFACE), PackageManager.GET_SERVICES | PackageManager.GET_META_DATA, userId);
    List<TvInputInfo> inputList = new ArrayList<>();
    for (ResolveInfo ri : services) {
        ServiceInfo si = ri.serviceInfo;
        if (!android.Manifest.permission.BIND_TV_INPUT.equals(si.permission)) {
            Slog.w(TAG, "Skipping TV input " + si.name + ": it does not require the permission " + android.Manifest.permission.BIND_TV_INPUT);
            continue;
        }
        ComponentName component = new ComponentName(si.packageName, si.name);
        if (hasHardwarePermission(pm, component)) {
            ServiceState serviceState = userState.serviceStateMap.get(component);
            if (serviceState == null) {
                // New hardware input found. Create a new ServiceState and connect to the
                // service to populate the hardware list.
                serviceState = new ServiceState(component, userId);
                userState.serviceStateMap.put(component, serviceState);
                updateServiceConnectionLocked(component, userId);
            } else {
                inputList.addAll(serviceState.hardwareInputList);
            }
        } else {
            try {
                TvInputInfo info = new TvInputInfo.Builder(mContext, ri).build();
                inputList.add(info);
            } catch (Exception e) {
                Slog.e(TAG, "failed to load TV input " + si.name, e);
                continue;
            }
        }
        userState.packageSet.add(si.packageName);
    }
    Map<String, TvInputState> inputMap = new HashMap<>();
    for (TvInputInfo info : inputList) {
        if (DEBUG) {
            Slog.d(TAG, "add " + info.getId());
        }
        TvInputState inputState = userState.inputMap.get(info.getId());
        if (inputState == null) {
            inputState = new TvInputState();
        }
        inputState.info = info;
        inputMap.put(info.getId(), inputState);
    }
    for (String inputId : inputMap.keySet()) {
        if (!userState.inputMap.containsKey(inputId)) {
            notifyInputAddedLocked(userState, inputId);
        } else if (updatedPackages != null) {
            // Notify the package updates
            ComponentName component = inputMap.get(inputId).info.getComponent();
            for (String updatedPackage : updatedPackages) {
                if (component.getPackageName().equals(updatedPackage)) {
                    updateServiceConnectionLocked(component, userId);
                    notifyInputUpdatedLocked(userState, inputId);
                    break;
                }
            }
        }
    }
    for (String inputId : userState.inputMap.keySet()) {
        if (!inputMap.containsKey(inputId)) {
            TvInputInfo info = userState.inputMap.get(inputId).info;
            ServiceState serviceState = userState.serviceStateMap.get(info.getComponent());
            if (serviceState != null) {
                abortPendingCreateSessionRequestsLocked(serviceState, inputId, userId);
            }
            notifyInputRemovedLocked(userState, inputId);
        }
    }
    userState.inputMap.clear();
    userState.inputMap = inputMap;
}
Also used : HashMap(java.util.HashMap) TvInputInfo(android.media.tv.TvInputInfo) ArrayList(java.util.ArrayList) Intent(android.content.Intent) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) OperationApplicationException(android.content.OperationApplicationException) ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) PackageManager(android.content.pm.PackageManager) ComponentName(android.content.ComponentName)

Example 8 with TvInputInfo

use of android.media.tv.TvInputInfo in project android_frameworks_base by ResurrectionRemix.

the class TvInputHardwareManager method dump.

public void dump(FileDescriptor fd, final PrintWriter writer, String[] args) {
    final IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ");
    if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) {
        pw.println("Permission Denial: can't dump TvInputHardwareManager from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
        return;
    }
    synchronized (mLock) {
        pw.println("TvInputHardwareManager Info:");
        pw.increaseIndent();
        pw.println("mConnections: deviceId -> Connection");
        pw.increaseIndent();
        for (int i = 0; i < mConnections.size(); i++) {
            int deviceId = mConnections.keyAt(i);
            Connection mConnection = mConnections.valueAt(i);
            pw.println(deviceId + ": " + mConnection);
        }
        pw.decreaseIndent();
        pw.println("mHardwareList:");
        pw.increaseIndent();
        for (TvInputHardwareInfo tvInputHardwareInfo : mHardwareList) {
            pw.println(tvInputHardwareInfo);
        }
        pw.decreaseIndent();
        pw.println("mHdmiDeviceList:");
        pw.increaseIndent();
        for (HdmiDeviceInfo hdmiDeviceInfo : mHdmiDeviceList) {
            pw.println(hdmiDeviceInfo);
        }
        pw.decreaseIndent();
        pw.println("mHardwareInputIdMap: deviceId -> inputId");
        pw.increaseIndent();
        for (int i = 0; i < mHardwareInputIdMap.size(); i++) {
            int deviceId = mHardwareInputIdMap.keyAt(i);
            String inputId = mHardwareInputIdMap.valueAt(i);
            pw.println(deviceId + ": " + inputId);
        }
        pw.decreaseIndent();
        pw.println("mHdmiInputIdMap: id -> inputId");
        pw.increaseIndent();
        for (int i = 0; i < mHdmiInputIdMap.size(); i++) {
            int id = mHdmiInputIdMap.keyAt(i);
            String inputId = mHdmiInputIdMap.valueAt(i);
            pw.println(id + ": " + inputId);
        }
        pw.decreaseIndent();
        pw.println("mInputMap: inputId -> inputInfo");
        pw.increaseIndent();
        for (Map.Entry<String, TvInputInfo> entry : mInputMap.entrySet()) {
            pw.println(entry.getKey() + ": " + entry.getValue());
        }
        pw.decreaseIndent();
        pw.decreaseIndent();
    }
}
Also used : HdmiDeviceInfo(android.hardware.hdmi.HdmiDeviceInfo) TvInputHardwareInfo(android.media.tv.TvInputHardwareInfo) TvInputInfo(android.media.tv.TvInputInfo) Map(java.util.Map) ArrayMap(android.util.ArrayMap) IndentingPrintWriter(com.android.internal.util.IndentingPrintWriter)

Aggregations

TvInputInfo (android.media.tv.TvInputInfo)8 ComponentName (android.content.ComponentName)4 Intent (android.content.Intent)4 OperationApplicationException (android.content.OperationApplicationException)4 PackageManager (android.content.pm.PackageManager)4 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)4 ResolveInfo (android.content.pm.ResolveInfo)4 ServiceInfo (android.content.pm.ServiceInfo)4 HdmiDeviceInfo (android.hardware.hdmi.HdmiDeviceInfo)4 TvInputHardwareInfo (android.media.tv.TvInputHardwareInfo)4 RemoteException (android.os.RemoteException)4 ArrayMap (android.util.ArrayMap)4 IndentingPrintWriter (com.android.internal.util.IndentingPrintWriter)4 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)4