Difference between revisions of "Patch webOS Radio Power Switch"

From WebOS Internals
Jump to navigation Jump to search
m (→‎Introduction: - Changed working OS versions)
(→‎Seamless Interface: updated patch and credits)
Line 34: Line 34:
  
 
<source lang="diff">
 
<source lang="diff">
--- /usr/lib/luna/system/luna-systemui/app/controllers/bar-assistant.js Sat Jul 18 00:21:30 2009
+
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/sys-mod/luna-systemui/app/controllers/bar-assistant.js Fri Jul 24 00:44:08 2009
+
--- /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 @@
 
@@ -789,6 +789,8 @@
 
  this.callForwardNotificationSession = null;
 
  this.callForwardNotificationSession = null;
Line 45: Line 46:
 
  else if (payload.eventNetwork && this.phoneRadioState) {
 
  else if (payload.eventNetwork && this.phoneRadioState) {
 
  var networkMsg = payload.eventNetwork;
 
  var networkMsg = payload.eventNetwork;
@@ -2570,6 +2572,10 @@
+
@@ -2572,6 +2574,10 @@
 +
return this.wifiState;
 +
},
 
   
 
   
getCurrentWiFiState: function() {
+
+getCurrentPhoneState: function() {
return this.wifiState;
+
+ return this.phoneRadioState;
 
+},
 
+},
 
+
 
+
+getCurrentPhoneState: function() {
+
setDeviceMenuAssistant: function(menuassistant) {
+ return this.phoneRadioState;
+
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
setDeviceMenuAssistant: function(menuassistant) {
+
--- /usr/lib/luna/system/luna-systemui/app/controllers/devicemenu-assistant.js 2009-07-18 00:21:30.000000000 -0500
--- /usr/lib/luna/system/luna-systemui/app/controllers/devicemenu-assistant.js Sat Jul 18 00:21:30 2009
+
+++ /usr/lib/luna/sysmod/luna-systemui/app/controllers/devicemenu-assistant.js 2009-07-24 10:46:55.000000000 -0500
+++ /usr/lib/luna/sys-mod/luna-systemui/app/controllers/devicemenu-assistant.js Fri Jul 24 00:50:25 2009
 
 
@@ -1,6 +1,6 @@
 
@@ -1,6 +1,6 @@
 
  /* Copyright 2009 Palm, Inc.  All rights reserved. */
 
  /* Copyright 2009 Palm, Inc.  All rights reserved. */
Line 75: Line 77:
 
  this.btdrawer = this.controller.get('btdetails');
 
  this.btdrawer = this.controller.get('btdetails');
 
 
 
 
@@ -92,6 +94,14 @@
+
@@ -92,6 +94,17 @@
 
  else
 
  else
 
  this.controller.get('wifimsg').innerHTML = wifistate.escapeHTML();
 
  this.controller.get('wifimsg').innerHTML = wifistate.escapeHTML();
Line 81: Line 83:
 
+
 
+
 
+ var phonestate = this.barAssistant.getCurrentPhoneState();
 
+ var phonestate = this.barAssistant.getCurrentPhoneState();
+ if(phoneState === 'Off') {
+
+ if(phonestate === 'Off') {
 
+ this.controller.get('phonemsg').innerHTML = $L('Off');
 
+ this.controller.get('phonemsg').innerHTML = $L('Off');
 
+ RadioState.set('phone',false);
 
+ RadioState.set('phone',false);
Line 93: Line 95:
 
  this.isVisible = true;
 
  this.isVisible = true;
 
 
 
 
@@ -115,6 +125,8 @@
+
@@ -115,6 +128,8 @@
 
  this.controller.get('btlist').addEventListener(Mojo.Event.listTap,this.handleBTTap.bindAsEventListener(this));
 
  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_wifi').addEventListener(Mojo.Event.tap, this.togglewifiList.bindAsEventListener(this));
Line 102: Line 104:
 
  this.controller.get('bt_radio').addEventListener(Mojo.Event.tap, this.toggleBTRadio.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));
 
  this.controller.get('bt_pref').addEventListener(Mojo.Event.tap,this.handleBluetoothLaunch.bindAsEventListener(this));
@@ -175,6 +187,48 @@
+
@@ -175,6 +190,48 @@
 
  this.apModeInProgress = false;
 
  this.apModeInProgress = false;
 
  },
 
  },
Line 151: Line 153:
 
  if(RadioState.get('bluetooth')) {
 
  if(RadioState.get('bluetooth')) {
 
  BtService.radiooff(null,null);
 
  BtService.radiooff(null,null);
@@ -880,7 +934,10 @@
+
@@ -880,7 +937,10 @@
 
  },
 
  },
 
 
 
 
Line 163: Line 165:
 
  this.clearBTList();
 
  this.clearBTList();
 
  this.controller.hideWidgetContainer(this.controller.get('btdetails'));
 
  this.controller.hideWidgetContainer(this.controller.get('btdetails'));
--- /usr/lib/luna/system/luna-systemui/app/views/devicemenu/devicemenu-scene.html Sat Jul 18 00:21:30 2009
+
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/sys-mod/luna-systemui/app/views/devicemenu/devicemenu-scene.html Fri Jul 24 00:52:11 2009
+
--- /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 @@
 
@@ -94,6 +94,22 @@
 
 
 
 
Line 194: Line 197:
 
* pEEf, for figuring everything out
 
* pEEf, for figuring everything out
 
* [[User:HattCzech|HattCzech]]
 
* [[User:HattCzech|HattCzech]]
 +
* NetWhiz, for fixing it to work with 1.1.0
  
 
== Concerns ==
 
== Concerns ==

Revision as of 17:55, 24 July 2009

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 <source lang="bash"> cd / sudo patch -p0 --backup-if-mismatch < ~/patches/radiopower.patch </source>

This is what you should see if it ran properly: <source lang="text"> 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 </source>

These modifications will require LunaSysMgr to be restarted. A rescan will not work. After you've run the commands above, run one more command: <source lang="bash"> pkill LunaSysMgr </source>

radiopower.patch

<source lang="diff"> 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 @@

+

+
+
 

+ Phone

+
+

+

+

+
+
+
+
+

+

+

+

</source>

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 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 [/stock-application-mods Modifiying 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.