Patch webOS Radio Power Switch

From WebOS Internals

Jump to: navigation, search


Contents

Seamless Interface

Radio Power Switch

Introduction

I took what pEEf did and made it look more like it fits. I liked the original idea, but as mentioned in the concerns below, when changing between Airplane mode and back, it doesn't have the correct information. I made mine look like the Bluetooth and Wi-Fi menus.

Works with: 1.0.x, 1.1

Procedure

Run the following commands:

In this example, I have the patch file located in my home directory under patches

cd /
sudo patch -p0 --backup-if-mismatch < ~/patches/radiopower.patch

This is what you should see if it ran properly:

patching file /usr/lib/luna/system/luna-systemui/app/controllers/bar-assistant.js
patching file /usr/lib/luna/system/luna-systemui/app/controllers/devicemenu-assistant.js
patching file /usr/lib/luna/system/luna-systemui/app/views/devicemenu/devicemenu-scene.html

These modifications will require LunaSysMgr to be restarted. A rescan will not work. After you've run the commands above, run one more command:

pkill LunaSysMgr

radiopower.patch

diff -ur /usr/lib/luna/system/luna-systemui/app/controllers/bar-assistant.js /usr/lib/luna/sysmod/luna-systemui/app/controllers/bar-assistant.js
--- /usr/lib/luna/system/luna-systemui/app/controllers/bar-assistant.js	2009-07-18 00:21:30.000000000 -0500
+++ /usr/lib/luna/sysmod/luna-systemui/app/controllers/bar-assistant.js	2009-07-24 00:44:08.000000000 -0500
@@ -789,6 +789,8 @@
 				this.callForwardNotificationSession = null;	
 			}				
 		}
+		var stageController = Mojo.Controller.getAppController().getStageProxy("DeviceMenu");
+		stageController.delegateToSceneAssistant("updatePhone");
 	}
 	else if (payload.eventNetwork && this.phoneRadioState) {
 		var networkMsg = payload.eventNetwork;
@@ -2572,6 +2574,10 @@
 	return this.wifiState;
 },
 
+getCurrentPhoneState: function() {
+	return this.phoneRadioState;
+},
+
 setDeviceMenuAssistant: function(menuassistant) {
 	this.deviceMenuAssistant = menuassistant;
 },
diff -ur /usr/lib/luna/system/luna-systemui/app/controllers/devicemenu-assistant.js /usr/lib/luna/sysmod/luna-systemui/app/controllers/devicemenu-assistant.js
--- /usr/lib/luna/system/luna-systemui/app/controllers/devicemenu-assistant.js	2009-07-18 00:21:30.000000000 -0500
+++ /usr/lib/luna/sysmod/luna-systemui/app/controllers/devicemenu-assistant.js	2009-07-24 10:46:55.000000000 -0500
@@ -1,6 +1,6 @@
 /* Copyright 2009 Palm, Inc.  All rights reserved. */
 
-var RadioState = new Hash({wifi: undefined, bluetooth: undefined});
+var RadioState = new Hash({wifi: undefined, bluetooth: undefined, phone: undefined});
 
 var DevicemenuAssistant = Class.create({
 
@@ -36,6 +36,8 @@
 		this.drawerModel = {myOpenProperty:false};
 		this.controller.setupWidget('wifidetails', {modelProperty:'myOpenProperty'}, this.drawerModel);
 		this.controller.setupWidget('btdetails', {modelProperty:'myOpenProperty'}, this.drawerModel);
+		this.controller.setupWidget('phonedetails', {modelProperty:'myOpenProperty'}, this.drawerModel);
+		this.phonedrawer = this.controller.get('phonedetails');
 		this.wifidrawer = this.controller.get('wifidetails');
 		this.btdrawer = this.controller.get('btdetails');
 
@@ -92,6 +94,17 @@
 			else
 				this.controller.get('wifimsg').innerHTML = wifistate.escapeHTML();			
 		}		
+		
+		var phonestate = this.barAssistant.getCurrentPhoneState();
+		if(phonestate === 'Off') {
+			this.controller.get('phonemsg').innerHTML = $L('Off');
+			RadioState.set('phone',false);
+		}
+		else {
+			this.controller.get('phonemsg').innerHTML = $L('On');
+			RadioState.set('phone',true);
+		}
+		
 		this.controller.listen(this.controller.document, Mojo.Event.deactivate, this.close.bindAsEventListener(this));
 		this.isVisible = true;
 
@@ -115,6 +128,8 @@
 		this.controller.get('btlist').addEventListener(Mojo.Event.listTap,this.handleBTTap.bindAsEventListener(this));		
 		this.controller.get('dm_wifi').addEventListener(Mojo.Event.tap, this.togglewifiList.bindAsEventListener(this));
 		this.controller.get('dm_bluetooth').addEventListener(Mojo.Event.tap, this.togglebluetoothList.bindAsEventListener(this));
+		this.controller.get('dm_phone').addEventListener(Mojo.Event.tap, this.togglePhoneList.bindAsEventListener(this));
+		this.controller.get('phone_radio').addEventListener(Mojo.Event.tap, this.togglePhoneRadio.bindAsEventListener(this));
 		this.controller.get('wifi_radio').addEventListener(Mojo.Event.tap, this.toggleWifiRadio.bindAsEventListener(this));
 		this.controller.get('bt_radio').addEventListener(Mojo.Event.tap, this.toggleBTRadio.bindAsEventListener(this));
 		this.controller.get('bt_pref').addEventListener(Mojo.Event.tap,this.handleBluetoothLaunch.bindAsEventListener(this));
@@ -175,6 +190,48 @@
 		this.apModeInProgress = false;
 	},
 
+	updatePhone: function() {
+		if(this.barAssistant.getCurrentPhoneState()) {
+			this.controller.get('phonemsg').innerHTML = $L('On');
+			this.controller.get('phone_radio').innerHTML = $L('Turn off Phone');
+			RadioState.set('phone', true);
+		}
+		else {
+			this.controller.get('phonemsg').innerHTML = $L('Off');
+			this.controller.get('phone_radio').innerHTML = $L('Turn on Phone');
+			RadioState.set('phone', false);
+		}
+	},
+	 
+	togglePhoneRadio: function(event) {
+		this.serviceRequest = new Mojo.Service.Request("palm://com.palm.vibrate", {
+			method: 'vibrate', parameters: { 'period': 0,'duration': 250 }
+		});
+		if(RadioState.get('phone'))
+			TelephonyService.tempPowerSet('off',false,null,null);
+		else
+			TelephonyService.tempPowerSet('on',false,null,null);
+		this.toggleDeviceMenu();
+	},
+	 
+	togglePhoneList: function(event) {
+		if(this.apModeInProgress)
+			return;
+	 
+		if (this.phonedrawer.mojo.getOpenState()) {
+			this.controller.hideWidgetContainer(this.controller.get('phonedetails'));	
+		}
+		else {
+			if(RadioState.get('phone'))
+				this.controller.get('phone_radio').innerHTML = $L('Turn off Phone');
+			else
+			this.controller.get('phone_radio').innerHTML = $L('Turn on Phone');	
+	 
+			this.controller.showWidgetContainer(this.controller.get('phonedetails'));
+		}
+		this.phonedrawer.mojo.setOpenState(!this.phonedrawer.mojo.getOpenState());						
+	},
+	
 	toggleBTRadio: function(event) {
 		if(RadioState.get('bluetooth')) {
 			BtService.radiooff(null,null);			
@@ -880,7 +937,10 @@
 	},
 
 	close: function() {
-		
+		if(this.phonedrawer.mojo.getOpenState()) {
+			this.controller.hideWidgetContainer(this.controller.get('phonedetails'));
+			this.phonedrawer.mojo.setOpenState(false);
+		}
 		if (this.btdrawer.mojo.getOpenState()) {
 			this.clearBTList();			
 			this.controller.hideWidgetContainer(this.controller.get('btdetails'));
diff -ur /usr/lib/luna/system/luna-systemui/app/views/devicemenu/devicemenu-scene.html /usr/lib/luna/sysmod/luna-systemui/app/views/devicemenu/devicemenu-scene.html
--- /usr/lib/luna/system/luna-systemui/app/views/devicemenu/devicemenu-scene.html	2009-07-18 00:21:30.000000000 -0500
+++ /usr/lib/luna/sysmod/luna-systemui/app/views/devicemenu/devicemenu-scene.html	2009-07-24 00:52:11.000000000 -0500
@@ -94,6 +94,22 @@
 
 				<div class="palm-section-divider"></div>
 
+				<div class="palm-row" id="dm_phone" x-mojo-tap-highlight='momentary'><div class="palm-row-wrapper">
+					<div class="title truncating-text">
+						<div class="label right" id="phonemsg">&nbsp;</div>
+						<span x-mojo-loc=''>Phone</span>
+					</div>
+				</div></div>
+				
+				<div id='phonedetails' x-mojo-element="Drawer">
+					<div class="palm-row first" x-mojo-tap-highlight='momentary'><div class="palm-row-wrapper">
+						<div id="phone_radio" class="title truncating-text">
+						</div>
+					</div></div>
+				</div>
+				
+				<div class="palm-section-divider"></div>
+				
 				<div id="dm_airplanemode" class="palm-row last" x-mojo-tap-highlight='momentary'><div class="palm-row-wrapper">
 					<div id="dm_airplanemode_status" class="title truncating-text">
 					 </div>

Acknowledgements

  • pEEf, for figuring everything out
  • HattCzech
  • NetWhiz, for fixing it to work with 1.1.0

Concerns

  • Airplane mode still always turns the radio on regardless of the state before airplane mode was turned on. Otherwise, very nice.
    • I may try to add in a way for it to remember the phone state, but I figured that was the point of Airplane mode, so I haven't looked into it yet. I will look through the code again and see if it's worth it. -HattCzech

Original Version

I created this mod so I can turn off the cellular radio, but keep WiFi and Bluetooth on. Strangely, The Pre does not seem to have an existing way to do this, only the "Airplane Mode" which shuts off ALL radios!

I currently do not have Sprint service on my Pre, and am just using it with WiFi. (See Bypassing Activation for info on how to do this.)

This will also be useful for people wishing to save their battery if in a poor or no service area, yet still wanting to use WiFi.

Another great use is shutting off the phone so calls will not disturb you while allowing the phone to do all of its network-related activity.

How it works: Simply click the upper right of the screen where the status bar is (signal strength). You will get a drop-down menu, this is where the stock "Airplane Mode" is. I have added a "Toggle Radio Power" function here. If the radio is on it will turn it off, and vice-versa. It will not turn off WiFi or Bluetooth like Airplane mode does.

Note

The Pre actually already lets you turn off the cell radio. You can just turn on Airplane Mode, then turn on WiFi, Bluetooth, or both. ~ lolaiba

Installation

NOTE: If you have never modified any code on the phone, please see Modifying Stock Applications first.

This mod is simply additional code to be added to 3 files on your Pre. WARNING: MAKE BACKUPS FIRST!

I will update the page later with proper diffs, but for now you can just get into the shell, make your backups, fire up vi (or nano) then paste in the relevant lines. Once you are done, you can test it without rebooting by forcing the Luna manager to reinitialize its cache:

luna-send -n 1 palm://com.palm.applicationManager/rescan {}

Here is the code, Enjoy!

/usr/lib/luna/system/luna-systemui/app/views/devicemenu/devicemenu-scene.html Line 94:

                                <div class="palm-section-divider"></div><!-- Added by pEEf -->

                                <div id="dm_power" class="palm-row" x-mojo-tap-highlight='momentary'><div class="palm-row-wrapper">
                                        <div id="dm_power_status" class="title truncating-text">   
                                         </div>
                                </div></div>

/usr/lib/luna/system/luna-systemui/app/controllers/bar-assistant.js Line 2039:

//Returns the Radio Power. Called by DeviceMenu. Added by pEEf        
getPower: function() {       
	return this.phoneRadioState;
},

/usr/lib/luna/system/luna-systemui/app/controllers/devicemenu-assistant.js Line 59:

//		Toggle for Radio Power - Added by pEEf
		if(this.barAssistant.getPower()) {
			this.controller.get('dm_power_status').innerHTML = $L('Turn off Phone Radio');
		}
		else {
			this.controller.get('dm_power_status').innerHTML = $L('Turn on Phone Radio');
		}

/usr/lib/luna/system/luna-systemui/app/controllers/devicemenu-assistant.js Line 107:

this.controller.get('dm_power').addEventListener(Mojo.Event.tap, this.togglePower.bindAsEventListener(this));

/usr/lib/luna/system/luna-systemui/app/controllers/devicemenu-assistant.js Line 126:

//	Toggles the Radio Power - Added by pEEf           

	togglePower: function() {
		this.serviceRequest = new Mojo.Service.Request("palm://com.palm.vibrate", {
			method: 'vibrate', parameters: { 'period': 0,'duration': 250 }
		});
		if(this.barAssistant.getPower()) {
			TelephonyService.tempPowerSet('off',false,null,null);
			this.controller.get('dm_power_status').innerHTML = $L('Turn on Phone Radio');
		}
		else {
			TelephonyService.tempPowerSet('on',false,null,null);
			this.controller.get('dm_power_status').innerHTML = $L('Turn off Phone Radio');
		}
		this.toggleDeviceMenu();
	},

Concerns

  • Turn off the radio, then turn on airplane mode, and upon turning off airplane mode, the toggle displays the wrong message.
  • Turn on airplane mode, toggle displays wrong message

Credits

Brought to you by pEEf.

Personal tools
Google AdSense