| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.hardware; |
| 18 |
|
| 19 |
import android.annotation.RequiresFeature; |
| 20 |
import android.annotation.SystemService; |
| 21 |
import android.content.Context; |
| 22 |
import android.content.pm.PackageManager; |
| 23 |
import android.os.RemoteException; |
| 24 |
import android.os.ServiceManager; |
| 25 |
import android.os.ServiceManager.ServiceNotFoundException; |
| 26 |
import android.util.Log; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
@SystemService(Context.CONSUMER_IR_SERVICE) |
| 32 |
@RequiresFeature(PackageManager.FEATURE_CONSUMER_IR) |
| 33 |
public final class ConsumerIrManager { |
| 34 |
private static final String TAG = "ConsumerIr"; |
| 35 |
|
| 36 |
private final String mPackageName; |
| 37 |
private final IConsumerIrService mService; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public ConsumerIrManager(Context context) throws ServiceNotFoundException { |
| 43 |
mPackageName = context.getPackageName(); |
| 44 |
mService = IConsumerIrService.Stub.asInterface( |
| 45 |
ServiceManager.getServiceOrThrow(Context.CONSUMER_IR_SERVICE)); |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public boolean hasIrEmitter() { |
| 54 |
if (mService == null) { |
| 55 |
Log.w(TAG, "no consumer ir service."); |
| 56 |
return false; |
| 57 |
} |
| 58 |
|
| 59 |
try { |
| 60 |
return mService.hasIrEmitter(); |
| 61 |
} catch (RemoteException e) { |
| 62 |
throw e.rethrowFromSystemServer(); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
public void transmit(int carrierFrequency, int[] pattern) { |
| 78 |
if (mService == null) { |
| 79 |
Log.w(TAG, "failed to transmit; no consumer ir service."); |
| 80 |
return; |
| 81 |
} |
| 82 |
|
| 83 |
try { |
| 84 |
mService.transmit(mPackageName, carrierFrequency, pattern); |
| 85 |
} catch (RemoteException e) { |
| 86 |
throw e.rethrowFromSystemServer(); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
public final class CarrierFrequencyRange { |
| 95 |
private final int mMinFrequency; |
| 96 |
private final int mMaxFrequency; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
public CarrierFrequencyRange(int min, int max) { |
| 105 |
mMinFrequency = min; |
| 106 |
mMaxFrequency = max; |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
public int getMinFrequency() { |
| 113 |
return mMinFrequency; |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
public int getMaxFrequency() { |
| 120 |
return mMaxFrequency; |
| 121 |
} |
| 122 |
}; |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
public CarrierFrequencyRange[] getCarrierFrequencies() { |
| 133 |
if (mService == null) { |
| 134 |
Log.w(TAG, "no consumer ir service."); |
| 135 |
return null; |
| 136 |
} |
| 137 |
|
| 138 |
try { |
| 139 |
int[] freqs = mService.getCarrierFrequencies(); |
| 140 |
if (freqs.length % 2 != 0) { |
| 141 |
Log.w(TAG, "consumer ir service returned an uneven number of frequencies."); |
| 142 |
return null; |
| 143 |
} |
| 144 |
CarrierFrequencyRange[] range = new CarrierFrequencyRange[freqs.length / 2]; |
| 145 |
|
| 146 |
for (int i = 0; i < freqs.length; i += 2) { |
| 147 |
range[i / 2] = new CarrierFrequencyRange(freqs[i], freqs[i+1]); |
| 148 |
} |
| 149 |
return range; |
| 150 |
} catch (RemoteException e) { |
| 151 |
throw e.rethrowFromSystemServer(); |
| 152 |
} |
| 153 |
} |
| 154 |
} |